LearnFrenzy
Sign in Take a free test

C Const · Exercise 2 of 4

C Const 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, so the answers are the real output.

Question 11 Medium

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int value = 1;
    const int *view = &value;
    int *edit = &value;
    *edit = 99;
    printf("%d\n", *view);
    return 0;
}
A 99
B 1
C Compilation error
D Undefined behaviour
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 ROWS = 2, COLS = 3;
    int grid[ROWS][COLS] = {};
    grid[ROWS - 1][COLS - 1] = 9;
    printf("%zu %d %d\n", sizeof grid / sizeof grid[0][0], grid[1][2], grid[0][0]);
    return 0;
}
A 6 9 0
B 6 9 garbage
C 5 9 0
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