segmentation fault for setting a variable equal to 0
I have a struct with two pointers and an int variable.For some reason i am
getting a segmentation fault if i keep the code ptr->i=0; if i take out
the statement ptr->i=0; i do not get a segmentation fault, why is that?
I'm pointing to something in the memory, i is not a pointer so it should
be legal. Can anyone please explain what is going on with this? ALSO I DID
CREATE MEMORY FOR THE STRUCT AND THE TWO CHAR POINTERS.
struct A_ {
char *a;
char *b;
int i;
};
typdef struct A_ StructA;
and then in my main() i have the following:
StructA *ptr;
ptr->i=0;
No comments:
Post a Comment