It is said that *
operator in C means "Pointer to a variable", and following code is legal:
#include <stdio.h>
int main(){
int a=5;
int *p=&a;
printf("%d\n", *p);
return 0;
}
But the following code is illegal:
#include<stdio.h>
struct pair{
int a,b;
};
int main(){
struct pair Alice, *Bob=&Alice;
Alice.a=1;
Alice.b=2;
printf("%d %d\n",*Bob.a,*Bob.b);
return 0;
}
So, why the *
operator works fine for pointers to normal variables, but does not work for pointers to structures?