I am experimenting with Struct, pointers and typedef in the code below. I want to create a pointer to a struct that I made up. Then I want to manipulate the struct's members using the -> operator.
The below code compiles fine, however, when I run the program it produces a segmentation fault.
Can someone please help explain where my logic went wrong?
Thank you.
struct Structure1 {
char c;
int i;
float f;
double d;
};
typedef Structure1* structp;
int main(){
structp s1, s2;
s1->c = 'a';
s1->i = 1;
s1->f = 3.14;
s1->d = 0.00093;
s2->c = 'a';
s2->i = 1;
s2->f = 3.14;
s2->d = 0.00093;
}