Welcome to the C# Operators and Expressions Quiz! This quiz is designed to test your understanding of key concepts related to operators and expressions in C#. You’ll encounter questions on arithmetic operators, assignment operators, operator precedence, logical operators, and more. Each question will challenge your knowledge and help reinforce essential programming skills as you work with variables, expressions, and operators in C#.
1.
What is the result of the following code?
string customerName = null;
string recipient = customerName ?? "Customer";
2.
What is the result of the following code?
3.
What is the purpose of the C# range operator (..)?
4.
Which of the following is a comparison operator in C#?
5.
What does the null-coalescing assignment operator (??=) do?
6.
What is the value of x after the following code?
7.
What is the result of the following code?
bool result = !(10 > 20);
8.
How does the increment operator (++) work in C# when placed before a variable?
9.
Which operator returns the result of a logical XOR (exclusive OR) in C#?
10.
What is the result of the following ternary expression?
int x = 10;
int y = 20;
Console.WriteLine(x < y ? "x is smaller" : "y is smaller");?
11.
What does the compound operator &= do?
12.
What is the result of the following expression?
13.
Which bitwise operator shifts bits to the left?
14.
What does the bitwise OR (|) operator do?
15.
What is the output of the following code?
int x = 171;
int y = 3;
int z = x & y;
16.
What does the bitwise NOT (~) operator do?
17.
Which operator is used to provide a default value if a variable is null?
18.
What is the output of the following code?
int x = 10;
int y = 20;
Console.WriteLine(x > y ? x : y);
19.
What does the logical OR (||) operator do?
20.
What is the result of the following expression?
bool result = (10 < 20) && (20 < 10);
21.
What does the comparison operator '==' return if two operands are equal?
22.
What is the value of y after the following code?
23.
What does the operator %= do in C#?
24.
Which operator has the lowest precedence in C#?
25.
What is the output of the following code?
int x = (10 + 20) * 10;
Console.WriteLine(x);
26.
How can you override the default operator precedence in C#?
27.
What is the result of the expression?
28.
What is the difference between the unary negative operator (-) and the subtraction operator (-) in C#?
29.
What is the value of x after the following code executes?
int x = 10;
int y = 20;
x += y;
30.
Which operator is used to assign a value to a variable in C#?