edited by
399 views
3 votes
3 votes

What will be the output of the following C program?

#include<stdio.h>
struct my_struct
{
    int field1;
    float field2;
    double field3;
};
int main()
{
    struct my_struct try1, try2;
    try1.field1 = 10.1;
    try1.field2 = 10.1;
    try1.field3 = 10.1;
    try2 = try1;
    printf("%d %.1f %.1lf",
    try2.field1, try2.field2, try2.field3);
} 
  1. $10\; 10.1\; 10.1$
  2. $10.1\; 10.1\; 10.1$
  3. Possible Runtime Error
  4. Garbage Value 
edited by

1 Answer

Best answer
3 votes
3 votes
.1f just means print only one digit after ".".
Here, 2 struct objects are created and "try2 = try1" copies all values of try1 to try2.

When a double value is assigned to an integer it automatically gets converted to an integer. So, "try1.field1 = "10.1" assigns "10" to field1. (Any fractional constant is by default taken as double unless it has an "f" suffix).

Correct Answer: A
selected by
Answer:

Related questions

9 votes
9 votes
1 answer
2
gatecse asked Jul 26, 2020
640 views
What will be the output of the following C program:#include<stdio.h int main() { char* disease = "COVID-19"; (*disease)++; printf("%s",disease); }DPWJE-$20$DOVID-$19$COVI...