The code is:

struct { int number; char symbol; } something[5]; something[0].number = 28; int *pointer = &something[0]; printf("%i", pointer -> number); 

The last line causes the error request for member 'number' in something not a structure or union .

Tried (*pointer).number - the same error. What could be her reason?

  • int *pointer = &something[0]; - this is nonsense. Do not ignore compiler messages. - AnT

1 answer 1

The reason for the error is that pointer is a pointer to an int , not a structure.

It would be correct to give the structure a certain name, and not to leave it anonymous:

 struct myStruct { int number; char symbol; } something[5]; struct myStruct *pointer = &something[0];