C - Pointers - Discussion

You Are Here :: Home > C > Pointers - Discussion

 



Q.

What will be output if you will execute following code?

#include
#define int int*
int main(){
int *p,q;
p=(int *)5;
q=10;
printf("%d",q+p);
return 0;
}

A. 10 B. 15
C. 20 D. 25

Answer: Option D
Explaination:

Here q pointer and p is a number.In c Address + number = Address

So, New address = old address + number * Size of data type to which pointer is pointing.
= 5 + 10 * sizeof (*int)
= 5+10*2 = 25.



Discussion

Your Comments Goes here...
NameDiscussion