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 variable without assigning a value in C#?
- A. num = int
- B. num int
- C. var num
- D. int num
Correct Answer: D
In C#, what is the default value of a boolean variable if not initialized explicitly?
- A. FALSE
- B. TRUE
- C. 0
- D. null
Correct Answer: A
What is the purpose of the 'dynamic' keyword in C#?
- A. To make a variable constant
- B. To specify a data type that can change during runtime
- C. To make a variable accessible outside its class
- D. To specify a data type to be determined at runtime
Correct Answer: D
In C#, which keyword is used to declare a variable that cannot be modified once it is assigned a value?
- A. readonly
- B. static
- C. const
- D. volatile
Correct Answer: C
What is the data type of the following variable declaration: var name = "John";
- A. object
- B. string
- C. int
- D. None of the above
Correct Answer: B
Which of the following is a valid variable name in C#?
- A. 123variable
- B. _variable
- C. myVariable
- D. Variable!
Correct Answer: C
What is the correct way to declare and initialize a constant in C#?
- A. int const VALUE = 10
- B. const VALUE = 10
- C. VALUE = const 10
- D. const int VALUE = 10
Correct Answer: D
Which of the following is a valid constant in C#?
- A. const float PI = 3.14
- B. readonly float PI = 3.14
- C. float const PI = 3.14
- D. const PI = 3.14
Correct Answer: A
What is the purpose of the 'volatile' keyword in C#?
- A. To define a constant
- B. To make a variable accessible outside its class
- C. To make a variable read-only
- D. To indicate that a variable's value can be modified by multiple threads concurrently
Correct Answer: D
In C#, which data type is used to represent characters and symbols?
- A. double
- B. int
- C. char
- D. string
Correct Answer: C
Which of the following is NOT a valid data type in C#?
- A. bool
- B. decimal
- C. long double
- D. char
Correct Answer: C
What is the correct way to declare a nullable integer variable in C#?
- A. num? int
- B. var? num
- C. int? num
- D. nullable int num
Correct Answer: C