CommerceVariables And Constants In C Sharp MCQs
Practice Variables And Constants In C Sharp MCQs for competitive exams.
Variables And Constants In C Sharp MCQs
Practice questions from this topic.
Which keyword is used to exit a loop prematurely in C#?
- A. continue
- B. skip
- C. exit
- D. break
Correct Answer: D
In C#, what is the result of the expression 3 / 2?
- A. 1
- B. 1.5
- C. 2
- D. 0
Correct Answer: A
What is the value of a variable in C# after it is declared but not assigned a value?
- A. Depends on the data type
- B. 0
- C. null
- D. undefined
Correct Answer: B
What is the purpose of declaring constants in C#?
- A. To store and manipulate data
- B. To declare variables
- C. To handle exceptions
- D. To define values that do not change
Correct Answer: D
Which of the following is a valid way to declare and initialize a string variable in C#?
- A. string = str
- B. str Hello
- C. string str = "Hello"
- D. str = "Hello"
Correct Answer: C
What is the scope of a global variable in C#?
- A. Limited to the block in which it is declared
- B. Throughout the program
- C. Limited to the file in which it is declared
- D. None of the above
Correct Answer: B
In C#, which keyword is used to declare a variable without specifying its data type explicitly?
- A. dynamic
- B. any
- C. var
- D. object
Correct Answer: C
Which of the following is NOT a valid constant name in C#?
- A. CONSTANT
- B. CONSTANT1
- C. _CONSTANT
- D. 1constant
Correct Answer: D
What is the default value of a boolean variable in C# if not initialized explicitly?
- A. FALSE
- B. TRUE
- C. 0
- D. Null
Correct Answer: A
What does the 'readonly' keyword do in C#?
- A. Makes a variable accessible outside its class
- B. Makes a variable constant
- C. Makes a variable read-only
- D. Makes a variable static
Correct Answer: C
Which keyword is used to define a constant in C#?
- A. static
- B. readonly
- C. final
- D. const
Correct Answer: D
What is the data type of the variable in C#?
- A. int
- B. string
- C. double
- D. char
Correct Answer: B