I have written the program to check the size of pointer expression. I am totally confused with pointers. Explain how does the compiler calculate the size of pointer expressions.
void main() {
int (*p)[20][30];
int (*q)[4];
int a[2][4];
int **r=a;
printf("%d %d %d\n", sizeof(**r),sizeof(*r),sizeof(r));
printf("%d %d %d\n", sizeof(a),sizeof(a[0]),sizeof(a[0][1]));
printf("%d %d %d\n", sizeof(q),sizeof(*q),sizeof(**q));
printf("%d %d %d\n", sizeof(p),sizeof(*p),sizeof(**p));
}
output
4 4 4
32 16 4
4 16 4
4 2400 120
int **r = a;isn't proper? The types are not compatible (and in fact, the assignment isn't needed for this question anyway, so you would do well to just remove it).int a[2][4]; int **r=a;is not valid code. An array of arrays of integers is not the same as an array of pointers to integers.%zu, not%dto print an argument of typesize_t(the type of the result of thesizeofoperator). Useint main(void), notvoid main(). Add#include <stdio.h>to the top of your program. Did you get a compiler warning onint **r = a;. If you didn't, increase the warning level on your compiler or get a better one. If you did, why didn't you mention that in your question? Warnings are important.