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.
What is the correct way to declare a constant string in C#?
- A. const MESSAGE = "Hello"
- B. MESSAGE const = "Hello"
- C. const string MESSAGE = "Hello"
- D. string MESSAGE = "Hello"
Correct Answer: C
Which of the following is a valid variable declaration in C#?
- A. num = int
- B. int num
- C. int = num
- D. None of the above
Correct Answer: B
What is the data type of the following variable declaration: var x = 10;
- A. dynamic
- B. var
- C. int
- D. object
Correct Answer: C
In C#, how do you declare a variable without initializing it?
- A. num = int
- B. num int
- C. var num
- D. int num
Correct Answer: D
What is the value of a variable after it is declared but not initialized in C#?
- A. Depends on the data type
- B. 0
- C. null
- D. undefined
Correct Answer: B
Which of the following is a valid constant name in C#?
- A. MAX_VALUE
- B. my-constant
- C. 123constant
- D. _CONSTANT
Correct Answer: A
What is the correct way to declare a floating-point variable in C#?
- A. var num
- B. Num float
- C. double num
- D. float num
Correct Answer: D
What is the purpose of a variable in C#?
- A. To handle exceptions
- B. To define a method
- C. To store and manipulate data
- D. To define a constant
Correct Answer: C
In C#, which keyword is used to declare a variable that can hold values of any data type?
- A. var
- B. dynamic
- C. any
- D. object
Correct Answer: B
Which data type is used to store whole numbers in C#?
- A. float
- B. double
- C. int
- D. char
Correct Answer: C
What is the scope of a local variable in C#?
- A. Limited to the file in which it is declared
- B. Limited to the class in which it is declared
- C. Limited to the method in which it is declared
- D. Limited to the block in which it is declared
Correct Answer: D
Which of the following is NOT a valid variable name in C#?
- A. 1variable
- B. _variable
- C. variable1
- D. Variable
Correct Answer: A