I am trying to figure out the sizeof(p)
where p
is the struct
defined below; but, when I try and run the following code:
#include <stdio.h>
struct p
{
char x;
int y;
};
int main()
{
printf("%d", sizeof(p));
return 0;
}
I receive this error:
main.c: In function ‘main’:
main.c:19:25: error: ‘p’ undeclared (first use in this function)
printf("%d", sizeof(p));
^
I am a beginner in C and I tried to move p
's definition into the main
function, changing the definition of p
, looking the error up online (none of the posts with the same error answered my question), etc., but I couldn't seem to get it to work. Any suggestions are appreciated.