Question
#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);
}
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);
}
Answer: Option D
Was this answer helpful ?
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 ?
Submit Solution