output for array of pointers is not giving correct values

This is a discussion on output for array of pointers is not giving correct values within the C Programming forums, part of the General Programming Boards category; HI ,
I am giving 1 and 2 inputs for below program.
output giving some other values as i exptectd.
...

That semi-colon means the if() is not associated with the following block, so i == 2 when it executes. This allocates and assigns p[2], which could cause a seg fault right there, but evidently it by chance does not.

The seg fault you get happens when the second if() loop starts, because p[0] was never initialized, therefore contains some random address which is dereferenced for a value (but it is out of bounds).