All three codes seem to work just fine, are any of them technically incorrect? I've read so much on arrays and pointers but at this stage I'm getting more and more confused!
I'd greatly appreciate it if someone can break down why the changes are allowed and which changes are not allowed.
Code:
int array[3]={30,40,50};
int *pointer_array[3];
for(int i=0;i<3;i++){
pointer_array[i]=&array[i];}
for(int i=0;i<3;i++){
printf("value of array[%d]= %d \n", i, *pointer_array[i]);}
Code:
int array[3]={30,40,50};
int *pointer_array[3];
for(int i=0;i<3;i++){
pointer_array[i]=array[i];} //removed &
for(int i=0;i<3;i++){
printf("value of array[%d]= %d \n", i, pointer_array[i]);} //removed *
Code:
int array[3]={30,40,50};
int *pointer_array; // removed [ ]
for(int i=0;i<3;i++){
pointer_array=array;} // removed & and [ ]
for(int i=0;i<3;i++){
printf("value of array[%d]= %d \n", i, pointer_array[i]);} // removed *