Sail E0 Webinar
Question

What will be output if you compile following c code ?


#include<stdio.h>
typedef struct
{
int i;
float f;
}temp;
temp alter(temp *ptr,int x,float y)
{
temp tmp = *ptr;
printf("%d %.2f\n",tmp.i,tmp.f);
tmp.i=x;
tmp.f=y;
return tmp;
}
void main()
{
temp a={65535,777.777};
a = alter(&a,-1,666.666);
printf("%d %.2f\n",a.i,a.f);
}




Options:
A .  Compile Error
B .  65535 777.777 -1 666.666
C .  65535 777.78 -1 666.67
D .  -1 777.78 -1 666.67
Answer: Option D

This program illustrates the transfer of a structure to a function by passing the structure's address (a pointer) to the function. Also the altered structure is now returned directly to the calling portion of the program.




Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers