K
Kavya
int main (){
int a[][3]={{1,2,3},{4,5,6}};
int (*ptr)[3]=a;
/* This should be fine and give 3 as output*/
printf("%d\n",(*ptr)[2]);
++ptr;
/* This should be fine and give 6 as output*/
printf("%d\n",(*ptr)[2]);
return 0;
}
But what if I do something like this
int main (){
int a[][3]={{1,2,3},{4,5,6}};
int (*ptr)[3]=a;
/* This should be fine and give 3 as output*/
printf("%d\n",(*ptr)[2]);
/* Will this be fine??
printf("%d\n",(*ptr)[5]);
return 0;
}
Is the second printf call in second code fine? or is it out of bound
access?
I tried both the codes with gcc 3.4.5 with -Wall and -pedantic. There
was no warning and got the correct output as 3 and 6 in both codes.
int a[][3]={{1,2,3},{4,5,6}};
int (*ptr)[3]=a;
/* This should be fine and give 3 as output*/
printf("%d\n",(*ptr)[2]);
++ptr;
/* This should be fine and give 6 as output*/
printf("%d\n",(*ptr)[2]);
return 0;
}
But what if I do something like this
int main (){
int a[][3]={{1,2,3},{4,5,6}};
int (*ptr)[3]=a;
/* This should be fine and give 3 as output*/
printf("%d\n",(*ptr)[2]);
/* Will this be fine??
printf("%d\n",(*ptr)[5]);
return 0;
}
Is the second printf call in second code fine? or is it out of bound
access?
I tried both the codes with gcc 3.4.5 with -Wall and -pedantic. There
was no warning and got the correct output as 3 and 6 in both codes.