NetApp Interview Question
Software Engineer / DevelopersThere is an implicit conversion from pointer to int.
"A pointer may be converted to an integral type. The size of integer required and the result are implementation defined. If the space provided is not long enough, the behavior is undefined."
If sizeof(int*) > sizeof(int), you have undefined behavior. If you have 64 bit pointers and 32 bit ints, on a big-endian machine the (undefined) result most likely would be 0.
But even if they are equal, the result is implementation defined (think segmented memory architecture).
int *p=0;
It means that p is a pointer to integer and has a value of 0.That means p is a pointer that points to the location 0 in the memory.Now when you increment the value of p it will increase by the value of its type which is 4(for integer pointer).
So the printf statement will o/p 4.
int main()
{
int *p,i=0;
p=&i;
printf("%u",p);
}
can u explain m d differnce b/w the code given and code given b m,
It will not print size . It will be converted into int and print 4. if we do printf("%d",p+2);
it will print 8
4 (Sizeof int)
- mlakshmanarao August 03, 2011The only reason for having datatypes for pointers. Becuase all pointers (Any data type) can hold address of memory which is always unsigned long/int. Then why to have data types for pointers? How manipulations on particular pointers has to be done.........for this reason data typoes are required for pointers.