Quote:
Originally Posted by
Raj 89
I have a problem with this code. I am using a gcc compiler and when i compile and execute this code i am getting a seg fault. I am just assigning two variables, name_1 as pointer and name_2 as string.
Yes, see, they're both pointers as far as the computer's concerned.
name_2 ends up being a pointer that points to 20 bytes of memory that can hold a string.
name_1 is a pointer that points nowhere in particular at all, and odds are good it will end up pointing at invalid memory.
Setting it to NULL will
guarantee it points to invalid memory.
C doesn't give you memory unless you ask for it.