Test Your Skills on C Operators

Practice Quiz

Practice Quiz
Practice quiz

Unlock the power of C programming by taking the quiz and embrace the confidence that comes with mastering this language. Believe in yourself, you've got this!

Before start, if you wish to refresh your knowledge on C operators, Click Here

1. What is the output of the following C code?

1
2
3
4
5
6
7
#include <stdio.h>
int main() {
    int x = 5;
    printf("%d ", x++);
    printf("%d", ++x);
    return 0;
}





The code will print "5 7" as output. The first printf statement prints the value of x (5) and then increments it by 1, and the second printf statement prints the incremented value of x (7).

2. What is the output of the following C code?

1
2
3
4
#include <stdio.h>
int main() {
    int x = 5;
    int y = ++x;
    printf("%d %d", x, y);
    return 0;
}





The code uses pre-increment in C, where 'x' is increased by 1 before being assigned to 'y'. Both 'x' and 'y' end up with the value of 6, so when printed, it shows "6 6" as the output.

3. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 10;
    int b = ++a;
    int c = a++;
    printf("%d %d %d", a, b, c);
    return 0;
}





The initial value of a is 10. The value of b is assigned the pre-incremented value of a, so b becomes 11. Then, the value of c is assigned the current value of a (which is now 11) before a is post-incremented, so c also becomes 11. The printf statement prints the values of a, b, and c, which are all 11.

4. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 5;
    int b = 10;
    int result;
    result = a || b;
    printf("%d", result);
    return 0;
}





The value of result is assigned the result of the logical OR operation (||) between a and b. Since a is 5 and b is 10, the result is 1 (true) because at least one of the operands is true. The correct answer is option C) 1.

5. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 5;
    int b = 10;
    int result;
    result = a && b;
    printf("%d", result);
    return 0;
}





The value of result is assigned the result of the logical AND operation (&&) between a and b. Since a is 5 and b is 10, both operands are true, so the result is 1 (true). The correct answer is option C) 1.

6. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 5;
    int b = 3;
    int result;
    result = a & b;
    printf("%d", result);
    return 0;
}





The value of result is assigned the result of the bitwise AND operation (&) between a and b. Since a is 5 (binary: 0101) and b is 3 (binary: 0011), the bitwise AND operation gives 1 (binary: 0001), which is 1 in decimal. The correct answer is option C) 1.

7. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 5;
    int b = 3;
    int result;
    result = a | b;
    printf("%d", result);
    return 0;
}





The value of result is assigned the result of the bitwise OR operation (|) between a and b. Since a is 5 (binary: 0101) and b is 3 (binary: 0011), the bitwise OR operation gives 7 (binary: 0111), which is 7 in decimal. The correct answer is option C) 7.

8. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 2;
    int b = 5;
    int result;
    result = a & b;
    printf("%d", result);
    return 0;
}





The value of result is assigned the result of the bitwise AND operation (&) between a and b. Since a is 2 (binary: 0010) and b is 5 (binary: 0101), the bitwise AND operation gives 0 (binary: 0000), which is 0 in decimal. The correct answer is option A) 0.

9. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 6;
    int b = 3;
    int result;
    result = a & b;
    printf("%d", result);
    return 0;
}





The value of result is assigned the result of the bitwise AND operation (&) between a and b. Since a is 6 (binary: 0110) and b is 3 (binary: 0011), the bitwise AND operation gives 2 (binary: 0010), which is 2 in decimal. The correct answer is option C) 3.

10. What is the output of the following C code?

1
2
3
#include <stdio.h>
int main() {
    int a = 10;
    int b = 5;
    int result;
    result = a < b;
    printf("%d", result);
    return 0;
}





The value of result is assigned the result of the relational operator < between a and b. Since a is 10 and b is 5, the expression a < b evaluates to false, which is represented as 0 in C. The correct answer is option B) 1.


Thank you for giving your best to answer! To explore more chapters, click the button below:

Master C Programming Index

Comments

Popular posts from this blog

Chapter 2: Unlocking the World of C

Chapter: 1 Programming..? What is it.?

Chapter 5: Tackling Typecasting, Decision Control in C