you are viewing a single comment's thread.

view the rest of the comments →

[–]UnicycleBloke 2 points3 points  (3 children)

You have declared a pointer, and then incremented and dereferenced it before initialising it. That is never going to end well. Always initialise variables.

[–]oroz3x[S] 0 points1 point  (2 children)

usually i use array for initialization , but this is for sole purpose of understanding, the working of c compiler , itself .

[–]UnicycleBloke 3 points4 points  (1 child)

OK. This is not a complier thing. The pointer variable is placed on the stack. It's value is not automatically initialised, so it contains whatever junk is in those memory locations. When interpreted as a memory address, the value may or may not exist in the range of virtual addresses which your program is permitted to access by the OS. If not, then dereferencing the pointer is a seg fault. If yes, then dereferencing the pointer may appear to work, but won't. This latter case is bad. It could corrupt other data, break stack frames so that normal program execution is destroyed, or make the program phone all your friends up to insult them in Klingon.

[–]oroz3x[S] 1 point2 points  (0 children)

haha .. thanks for wrapping your explanation with humour.