LearnFrenzy
Sign in Take a free test

Operators and Expressions · Exercise 2 of 4

Operators and Expressions 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, so the answers are the real output.

Question 1 Easy

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int a = 5, b;
    b = a++ * 2;
    printf("%d %d\n", a, b);
    return 0;
}
A 6 10
B 6 12
C 5 10
D 6 11
Question page & discussion
Question 2 Medium

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    printf("%d\n", 10 - 4 - 3 * 2 + 8 / 4 % 3);
    return 0;
}
A 2
B 0
C 4
D -2
Question page & discussion
Question 3 Hard

What is the output of the following C program?

main.c
#include <stdio.h>

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

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int x = 5;
    printf("%d %d %d\n", !x + 1, !(x + 1), !!x);
    return 0;
}
A 1 0 1
B 0 0 5
C 6 0 1
D 1 1 1
Question page & discussion
Question 5 Hard

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int x = (1, 2, 3);
    int y;
    y = 4, 5;
    printf("%d %d\n", x, y);
    return 0;
}
A 3 4
B 1 5
C 3 5
D 1 4
Question page & discussion
Question 6 Medium

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    printf("%d %.2f %.2f\n", 7 / 2 * 2, 7 / 2 * 2.0, 7 / 2.0 * 2);
    return 0;
}
A 6 6.00 7.00
B 7 7.00 7.00
C 6 7.00 7.00
D 6 6.00 6.00
Question page & discussion
Question 7 Hard

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int x = 0;
    int r = x++ || x++;
    printf("%d %d\n", r, x);
    return 0;
}
A 1 2
B 0 1
C 1 1
D 0 2
Question page & discussion
Question 8 Medium

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int a = 5, b = 8;
    int r = a > b ? a : b > 6 ? b * 2 : b;
    printf("%d\n", r);
    return 0;
}
A 16
B 8
C 5
D 10
Question page & discussion
Question 9 Hard

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    char c = 'A';
    printf("%zu %zu %zu\n", sizeof c, sizeof(c + 1), sizeof(c = 'B'));
    printf("%c\n", c);
    return 0;
}
A 1 4 1 A
B 1 1 1 B
C 1 4 4 A
D 1 4 1 B
Question page & discussion
Question 10 Medium

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int a = -7;
    printf("%d %d %d\n", -a % 3, a / -2, -(a % 4));
    return 0;
}
A 1 3 3
B -1 3 3
C 1 -3 3
D 1 3 -3
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links