What happens if you try to compile and run this program?

What happens if you try to compile and run this program?

#include <stdio.h>

#include <string.h>

struct STR {

int i;

char c[20];

float f;

};

int main (int argc, char *argv[]) {

struct STR str = { 1, "Hello", 3 };

printf("%d", str.i + strlen(str.c));

return 0;

}

Choose the right answer:
A . The program outputs 4
B . The program outputs 1
C . The program outputs 5
D . The program outputs 6
E . Compilation fails

Answer: D

Explanation:

The program defines a structure named STR that contains three members: an int, a char array, and a float. Then it creates a variable of type struct STR named str and initializes its members with the values 1, “Hello”, and 3. The program then prints the value of str.i + strlen(str.c), which is the sum of the int member and the length of the char array member. The length of the string “Hello” is 5, so the expression evaluates to 1 + 5 = 6. Therefore, the program outputs 6. References = C struct (Structures) – Programiz, C Structures (structs) – W3Schools, C Structures – GeeksforGeeks

Latest CLA-11-03 Dumps Valid Version with 40 Q&As

Latest And Valid Q&A | Instant Download | Once Fail, Full Refund

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments