LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Exercise 2 of 4

Declarations and Initializations 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 <stdio.h>

int main(void) {
    struct { int a, b; } s1 = {1, 2}, s2;
    s2 = s1;
    s2.b = 9;
    printf("%d %d\n", s1.b, s2.b);
    return 0;
}
A 2 9
B 9 9
C 2 2
D Compilation error
Question page & discussion
Question 12 Hard

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

main.c
#include <stdio.h>

int main(void) {
    constexpr int SIZE = 4;
    auto half = SIZE / 2.0;
    typeof(half) twice = half * 2;
    printf("%.1f %zu %.1f\n", half, sizeof twice, twice);
    return 0;
}
A 2.0 8 4.0
B 2.0 4 4.0
C 2 8 4
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