Syntax in C++ MCQs Exercise I

Ques 1 Syntax


Which of the following is the correct way to declare an integer variable named "num" in C++?

A int num;
B integer num;
C num = int;
D declare num as integer;

b) integer num; - This is incorrect because "integer" is not a valid data type in C++. The correct keyword for integers is "int".
c) num = int; - This is incorrect because it is assigning the keyword "int" to the variable "num". The correct way to initialize a variable is to assign a value to it, not a data type.
d) declare num as integer; - This is not a valid C++ syntax. To declare a variable, you need to use the appropriate keyword (in this case, "int") followed by the variable name.
So, a) is the correct option

Ques 2 Syntax


How do you initialize an array of integers named "arr" with values 1, 2, 3, and 4 in C++?

A int arr[4] = {1, 2, 3, 4};
B arr = [1, 2, 3, 4];
C int arr = {1, 2, 3, 4};
D int arr[] = {1, 2, 3, 4};

Ques 3 Syntax


In C++, how can you pass the address of a variable to a function?

A By using the & symbol before the variable name.
B By using the * symbol before the variable name.
C By enclosing the variable name in square brackets.
D By enclosing the variable name in curly braces.

Ques 4 Syntax


What is the purpose of the "const" keyword in C++?

A It defines a constant value.
B It declares a variable with a fixed memory address.
C It specifies that a function cannot be modified.
D It indicates that a variable's value cannot be changed.

The const keyword in C++ is used to declare variables or objects whose values cannot be modified after initialization. This helps prevent accidental changes to important data and improves code reliability.
So, d) It indicates that a variable's value cannot be changed. is correct answer.