I am a C beginner, and I am curious why this gives me a Seg Fault everytime:
#include <stdio.h>
#include <stdlib.h>
struct Wrapper {
int value;
};
int main () {
struct Wrapper *test;
test->value = 5;
return 0;
}
I know I don't fully understand pointers yet, but I thought that
struct_ptr->field
is the same as
(*struct_ptr).field
so trying to make an assignment right to the field should be ok. This works like expected:
struct Wrapper test;
test.value = 5;
but I am curious why using the pointer causes a Seg Fault.
I am on Ubuntu 9.04 (i486-linux-gnu), gcc version 4.4.1