LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Exercise 2 of 4

Declarations and Initializations Predict the Output

  • 12 questions
  • Page 1 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 1 Medium

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

main.c
#include <stdio.h>

int main(void) {
    int* a, b;
    printf("%zu %zu\n", sizeof a, sizeof b);
    return 0;
}
A 8 4
B 8 8
C 4 4
D 4 8
Question page & discussion
Question 2 Medium

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

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

int main(void) {
    int a[5] = {[1] = 4, 7};
    char s[6] = "ab";
    printf("%d %d %d %d %zu %d\n", a[0], a[1], a[2], a[4], strlen(s), s[4]);
    return 0;
}
A 0 4 7 0 2 0
B 4 7 0 0 2 0
C 0 4 0 7 2 0
D 0 4 7 0 6 0
Question page & discussion
Question 3 Hard

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

main.c
#include <stdio.h>

struct date {
    int d, m, y;
};

int main(void) {
    struct date dt = {.m = 8, 2026};
    printf("%d %d %d\n", dt.d, dt.m, dt.y);
    return 0;
}
A 0 8 2026
B 2026 8 0
C 8 2026 0
D Compilation error
Question page & discussion
Question 4 Easy

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

main.c
#include <stdio.h>

extern int n;

int twice(void) { return n * 2; }

int n = 21;

int main(void) {
    printf("%d\n", twice());
    return 0;
}
A 42
B 0
C Compilation error
D Garbage
Question page & discussion
Question 5 Medium

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

main.c
#include <stdio.h>

int main(void) {
    printf("%zu %zu %zu\n", sizeof 10, sizeof 10.0f, sizeof "C23");
    return 0;
}
A 4 4 4
B 4 8 3
C 2 4 4
D 4 4 3
Question page & discussion
Question 6 Medium

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

main.c
#include <stdio.h>

int main(void) {
    int i = 7.9;
    double d = 7 / 2;
    char c = 65 + 1;
    printf("%d %.1f %c\n", i, d, c);
    return 0;
}
A 7 3.0 B
B 8 3.5 B
C 7 3.5 A
D 7 3.0 A
Question page & discussion
Question 7 Easy

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

main.c
#include <stdio.h>

enum level { LOW = 1, MID, HIGH = 10, MAX };

int main(void) {
    printf("%d %d %d\n", MID, HIGH, MAX);
    return 0;
}
A 2 10 11
B 1 10 11
C 2 3 4
D 2 10 3
Question page & discussion
Question 8 Medium

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

main.c
#include <stdio.h>

int main(void) {
    int *p = (int[]){1, 2, 3};
    p[0] = 9;
    printf("%d %d\n", p[0], *(p + 2));
    return 0;
}
A 9 3
B 1 3
C 9 2
D The program crashes
Question page & discussion
Question 9 Medium

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

main.c
#include <stdio.h>

int main(void) {
    char a[] = "hello";
    char b[10] = "hello";
    const char *c = "hello";
    printf("%zu %zu %zu\n", sizeof a, sizeof b, sizeof c);
    return 0;
}
A 6 10 8
B 5 10 5
C 6 6 6
D 6 10 6
Question page & discussion
Question 10 Hard

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

main.c
#include <stdio.h>

int count;
int count;
int count = 5;

int main(void) {
    printf("%d\n", count);
    return 0;
}
A 5
B 0
C Compilation error: redefinition
D Garbage
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links