I created a structure with two elements and tried to assign a value to one of the structure elements outside main function. But I'm getting error while compiling.
#include <stdio.h>
#include <stdlib.h>
struct node{
char a;
int b;
};
struct node sr;
sr.b = 48;
int main(){
printf("Value:%d",sr.b);
return 0;
}
I'm assigning value after the declaration. Why is this code giving error.
error message
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token