sum with a pointer

Hi all,
i've got some problems with pointers if i write:


int* plen;

/* some code */

*plen = *plen + sizeof(struct ip) + sizeof(struct tcphdr)


it terms with a segmentation fault exactly on that operation (i saw it with gdb)

somebody can explain me why?

tnx in advance.
You are using an uninitialised pointer.

You should first make the pointer point to some existing integer:
1
2
 int a;
plen = &a;


or
create an integer using new plen = new int;
you should also initialise the new int or assign it some known value before you carry out the operation in line 3 of your code, because that operation takes the existing value of *plen and adds to it.

Topic archived. No new replies allowed.