NetApp Interview Question
Software Engineer / DevelopersCountry: India
no,... pointer c will be pointing to some garbage location in the memory if u haven't initialized it ....so at every run for *c and c there may be different values... in the case when your pointer is containing null address and u tries to dereference it ,then it will produce segmentaion fault.
>>For &c you are right.
Not really.
&C should print the same location. However, if the OS is doing stack randomization, yes, you will see different values. So this depends on each OS implementation.
printf("\n%d", *c) - Mostly results in segmentation fault, i.e., you are trying to access memory location which is not allowed . Mostly the program terminates here but in case the pointer variable has some valid address then program prints that valid data pointed by c and proceed to execute next line of code.
printf("\n%d", c) - prints the content of the pointer variable; because the variable is not intialized, we will find a junk value
printf("\n%d", &c) - prints the address of the pointer varible 'c'
In printf of *c when you try to dereference an uninitialized pointer, you are most likely to access some address which is not part of your allocated stack and you will get Seg Fault.
- Anonymous October 04, 2011For &c you are right. It can get allocated any where on the stack where compiler finds some space for it.