WorksheetsC++ Programming Quiz-Basics
Total questions: 35
Worksheet time: 20mins
C++ is a:
Procedure-oriented language
Object-oriented language
Assembly language
Markup language
Which of the following is the correct file extension for C++?
.c
.java
.cpp
.py
Which symbol is used to end a statement in C++?
:
.
;
,
Which header file is required for cout and cin?
Which keyword is used to define a constant in C++?
var
let
const
define
Which of the following is used to display output in C++?
cin
printf
cout
scanf
Which operator is used for input in C++?
>
<
=
==
Which of the following is a valid C++ variable name?
2num
num-1
num_1
num 1
Which keyword is used to declare a class in C++?
struct
object
class
define
Which of the following is NOT a C++ data type?
int
float
string
real
What is the correct syntax to start the main function?
void main()
main()
int main()
start()
Which operator is used for comparison?
=
==
!=
Both B and C
Which loop executes at least once?
for
while
do-while
foreach
Which of the following is used for comments in C++?
/* */
//
#
Both A and B
Which concept allows function overloading in C++?
Inheritance
Polymorphism
Encapsulation
Abstraction
Which keyword is used to define a structure in C++?
structure
struct
class
define
Members of a structure are public by default.
True
False
In a union, how many members can store values at a time?
All members
Only one member
Two members
Depends on compiler
Which keyword is used to define a union?
struct
class
union
object
Which of the following correctly declares an integer array of size 5?
int arr;
int arr(5);
int arr[5];
array int[5];
Array indexing in C++ starts from:
1
0
−1
Depends on data type
Which keyword is used to define a class in C++?
struct
object
class
define
Members of a class are ______ by default.
public
protected
private
static
How is an object created for a class Student?
Student();
class Student s;
Student s;
object Student s;
Which operator is used to access data members of a class using an object?
:
::
.
->
What is the output of the following code: int x = 10; cout << x;
0
10
x
Error
Output of the following code: int x = 5; cout << x++;
6
5
Error
4
Output of the following code: int a[3] = {10, 20, 30}; cout << a[2];
10
20
30
Error
Output of the following code: for(int i = 0; i < 3; i++) cout << i;
123
012
321
013
Output of the following code: int x = 0; if(x) cout << "Yes"; else cout << "No";
Yes
No
0
Error
Output of the following code: struct Test { int a; }; int main() { Test t; t.a = 7; cout << t.a; }
0
7
Garbage value
Error
Output of the following code: class Demo { public: int x = 5; }; int main() { Demo d; cout << d.x; }
0
5
Error
Garbage value
Output of the following code: int x = 3; cout << ++x;
3
4
5
Error
Output of the following code: union Data { int a; char b; }; int main() { Data d; d.a = 66; cout << d.b; }
66
B
A
Error
Output of the following code: int fun() { return 10; } int main() { cout << fun(); }
fun
0
10
Error
