What is the correct syntax to declare an array in C++?
A. int arrayName[size];
B. array arrayName[size];
C. arrayName[size];
D. int[size] arrayName;
Answer: A
Which keyword is used to define a class in C++?
A. class
B. struct
C. typedef
D. using
Answer: A
Which of the following is not a valid data type in C++?
A. int
B. float
C. char
D. string
Answer: D
What is the correct way to initialize a constant variable in C++?
A. const int num = 10;
B. int const num = 10;
C. const int = 10;
D. int = const 10;
Answer: A
Which operator is used to access the member functions and variables of a class in C++?
A. *
B. .
C. ::
D. ->
Answer: D
What is the output of the following code?
Copy code
int num = 10;
cout << num++ << endl;
A. 10
B. 11
C. Compiler error
D. Undefined behavior
Answer: A
Which of the following is an example of a post-test loop in C++?
A. while loop
B. do-while loop
C. for loop
D. if-else statement
Answer: B
What is the output of the following code?
Copy code
int num = 10;
cout << ++num << endl;
A. 10
B. 11
C. Compiler error
D. Undefined behavior
Answer: B
Which of the following is used to allocate dynamic memory in C++?
A. new operator
B. malloc function
C. calloc function
D. realloc function
Answer: A
What is the output of the following code?
Copy code
int arr[] = {1, 2, 3, 4, 5};
cout << *arr << endl;
A. 1
B. 2
C. 5
D. Compiler error
Answer: A
eisha tariq
more
Which keyword is used to define a function in C++?
A. method
B. subroutine
C. function
D. procedure
Answer: C
What is the output of the following code?
Copy code
int num1 = 10, num2 = 20;
cout << (num1 > num2) << endl;
A. 0
B. 1
C. Compiler error
D. Undefined behavior
Answer: A
Which of the following is used to terminate a switch statement in C++?
A. break
B. continue
C. return
D. exit
Answer: A
What is the output of the following code?
Copy code
int num = 5;
cout << sizeof(num++) << endl;
cout << num << endl;
A. 4 5
B. 5 5
C. 4 6
D. 5 6
Answer: A
Which of the following is a preprocessor directive in C++?
A. using
B. typedef
C. include
D. const
Answer: C
What is the output of the following code?
Copy code
int arr[] = {1, 2, 3, 4, 5};
cout << *(arr + 2) << endl;
A. 1
B. 2
C. 3
D. 4
Answer: C
Which keyword is used to define a constant in C++?
A. var
B. constant
C. const
D. readonly
Answer: C
What is the output of the following code?
Copy code
int num = 10;
cout << (num == 10 ? "true" : "false") << endl;
A. true
B. false
C. Compiler error
D. Undefined behavior
Answer: A
Which of the following is a standard input/output library in C++?
A. iostream
B. string
C. vector
D. algorithm
Answer: A
What is the output of the following code?
Copy code
int arr[] = {1, 2, 3, 4, 5};
cout << arr[5] << endl;
A. 0
B. 1
C. Compiler error
D. Undefined behavior
Answer: D
eisha tariq
more 30
Which of the following is a type of loop in C++?
A. repeat-until loop
B. while loop
C. for-each loop
D. all of the above
Answer: B
What is the output of the following code?
Copy code
int num = 10;
cout << num-- << endl;
A. 10
B. 9
C. Compiler error
D. Undefined behavior
Answer: A
Which of the following is a type of function in C++ that does not return a value?
A. void function
B. value-returning function
C. constructor function
D. destructor function
Answer: A
What is the output of the following code?
Copy code
int num1 = 10, num2 = 20;
cout << (num1 < num2) << endl;
A. 0
B. 1
C. Compiler error
D. Undefined behavior
Answer: B
Which of the following is used to define a constructor in C++?
A. void constructor()
B. constructor()
C. class constructor()
D. ClassName()
Answer: D
What is the output of the following code?
Copy code
int num1 = 10, num2 = 20;
cout << (num1 != num2) << endl;
A. 0
B. 1
C. Compiler error
D. Undefined behavior
Answer: B
Which of the following is used to declare a pointer variable in C++?
A. varType* ptrName;
B. varType ptrName*;
C. ptrName* varType;
D. ptrName varType*;
Answer: A
What is the output of the following code?
Copy code
int arr[] = {1, 2, 3, 4, 5};
cout << arr[0] << endl;
A. 1
B. 5
C. Compiler error
D. Undefined behavior
Answer: A
Which of the following is a type of function in C++ that returns a value?
A. void function
B. value-returning function
C. constructor function
D. destructor function
Answer: B
What is the output of the following code?
Copy code
int num1 = 10, num2 = 20;
cout << (num1 >= num2) << endl;
A. 0
B. 1
C. Compiler error
D. Undefined behavior
Answer: A