C Programming Reference
 
C Programming Reference >> C  Programming Reference Question Bank >>

19/07/07 - 6353 Views - Ratings :   5 of 5 / 2 Votes

Level - Begineers
      

Question -

Predict  the output of the following code.
#include <stdio.h>

int main() { char *p; char buf[10] = { 1,2,3,4,5,6,9,8} ; p = (buf+1)[5]; printf("%d" , p); }
Answer -
 9
Explanation -

Simple question considering the fact that in C programming language the base address of the array is the name of the array without brackets. Now (buf+1) [5] is exactly same as (buf+6). When this memmory location is accessed it returns the value stored in the seventh postion in the array and that would be 9.

 

Reader Comments -

Author Comments
Add Comments 


Name :    
Reply :   


Rating :

Code :
Code

 

 
© 2006 cencyclopedia.com