LearnFrenzy
Sign in Take a free test

Structures, Unions, Enums · Exercise 2 of 4

Structures, Unions, Enums Predict the Output

  • 12 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each program and choose what it prints. Every program was compiled and run on a 64-bit system, so the answers are the real output.

Question 11 Medium

What is the output of the following C program on a 64-bit system?

main.c
#include <stddef.h>
#include <stdio.h>

struct rec {
    char tag;
    int id;
    double score;
};

int main(void) {
    printf("%zu %zu %zu\n", offsetof(struct rec, id), offsetof(struct rec, score), sizeof(struct rec));
    return 0;
}
A 1 5 13
B 4 8 13
C 8 16 24
D 4 8 16
Question page & discussion
Question 12 Hard

What is the output of the following program, compiled as C23?

main.c
#include <stdio.h>

enum small : unsigned char { S0, S1 = 200, S2 };

int main(void) {
    enum small x = S2;
    printf("%zu %d\n", sizeof x, x);
    return 0;
}
A 4 201
B 1 2
C 1 201
D Compilation error
Question page & discussion
Up next · Exercise 3Find the Error8 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links