Sail E0 Webinar
Question

What will be output if you compile following c code ?


#include<stdio.h>
struct
{
int i,val[25];
float f;
}var={1,2,3,4,5,6,7,8,9},*vptr=&var;
void main()
{
printf("%d %d %d\n",var.i,vptr->i,(*vptr).i);
printf("%d %d %d %d %d %d",var.val[4], var.val+4), vptr->val[4],*(vptr->val+4),
(*vptr).val[4], *((*vptr).val+4));
}


Options:
A .  Compile Error
B .  1 1 16 6 6 6 6 6
C .  1 1 15 5 5 5 5 5
D .  None of these
Answer: Option B

Since value of the member 'i' can be accessed using var.i, vptr->i and (*vptr).i  Similarly 5th value of the member 'val' can be accessed using var.val[4], *(var.val+4), vptr->val[4], *(vptr->val+4), (*vptr).val[4] and *((*vptr).val+4)



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers