1. What is the result of the expression 5 + 3 * 2 in C?
Answer:
Explanation:
According to operator precedence in C, multiplication is performed before addition. Hence, 3 * 2 is evaluated first, making the expression 5 + 6, which equals 11.
2. What does the '++' operator do in C?
Answer:
Explanation:
The '++' operator increments the value of a variable by 1.
3. Which of the following is a logical operator in C?
Answer:
Explanation:
The '!' operator is a logical NOT operator in C. The '&' and '|' are bitwise operators, and '%' is the modulo operator.
4. What is the purpose of the bitwise AND operator '&' in C?
Answer:
Explanation:
The '&' operator performs a bitwise AND operation, comparing each bit of its first operand to the corresponding bit of its second operand.
5. Which operator is used for division in C?
Answer:
Explanation:
The '/' operator is used for division in C.
6. What does the '==' operator do in C?
Answer:
Explanation:
The '==' operator is used to compare two values to determine if they are equal.
7. What is the result of the expression 8 % 3 in C?
Answer:
Explanation:
The '%' operator returns the remainder of the division of 8 by 3, which is 2.
8. What is the output of the following C code?
int a = 5, b = 10;
printf("%d", a > b && a != b);
Answer:
Explanation:
The expression evaluates to false (0) because a is not greater than b, even though a is not equal to b.
9. Which operator is used to check if two variables are not equal in C?
Answer:
Explanation:
The '!=' operator checks if two variables are not equal.
10. What is the purpose of the conditional (ternary) operator '?:' in C?
Answer:
Explanation:
The ternary operator '?:' is used to assign a value to a variable based on a condition. It's a shorthand for the if-else statement.
11. How does the bitwise OR operator '|' work in C?
Answer:
Explanation:
The '|' operator performs a bitwise OR operation, where a bit is set to 1 if it is set in either operand.
12. What is the result of the expression 5 << 2 in C?
Answer:
Explanation:
The '<<' operator is the left shift operator. It shifts the bits of 5 (which is 0101 in binary) 2 places to the left, resulting in 10100, which is 20 in decimal.
13. What is the precedence of the '+' and '*' operators in C?
Answer:
Explanation:
In C, the '*' (multiplication) operator has higher precedence than the '+' (addition) operator.
14. What does the 'sizeof' operator return in C?
Answer:
Explanation:
The 'sizeof' operator returns the size of a variable or data type in bytes.
15. What is the output of the following C code?
int x = 9, y = 4;
printf("%d", x & y);
Answer:
Explanation:
The '&' operator performs a bitwise AND operation. In binary, 9 is 1001 and 4 is 0100. The AND operation of these gives 0001, which is 5 in decimal.
16. What is the result of the expression 5 | 3 in C?
Answer:
Explanation:
The '|' operator performs a bitwise OR operation. In binary, 5 is 0101 and 3 is 0011. The OR operation of these gives 0111, which is 7 in decimal.
17. What is the output of the following C code?
int a = 10;
printf("%d", !a);
Answer:
Explanation:
The '!' operator is the logical NOT operator. It inverts the truthiness of a, and since a is non-zero, !a is 0.
18. What does the '->' operator do in C?
Answer:
Explanation:
The '->' operator is used to access a member of a structure or a union through a pointer.
19. What is the result of the expression '5 == 5' in C?
Answer:
Explanation:
The '==' operator compares two values for equality. Since 5 is equal to 5, the expression evaluates to true (1).
20. What is the output of the following C code?
int a = 5;
int b = a++;
printf("%d %d", a, b);
Answer:
Explanation:
The post-increment operator 'a++' increments 'a' after its current value is assigned to 'b'. So, 'b' becomes 5, and 'a' becomes 6.
Comments
Post a Comment
Leave Comment