WorksheetsProgramming Fundamentals
Total questions: 30
Worksheet time: 13mins
Which of the following is a valid C++ identifier?
2value
value_2
int
for
Which header file is required for cout and cin?
A) stdio.h
B) iostream
C) conio.h
D) stdlib.h
What is the default value of an uninitialized local variable in C++?
0
Garbage value
NULL
-1
Which data type is best for storing a single character?
string
char
char[]
bool
What will sizeof(int) typically return?
1
2
4
Depends on compiler
Which type conversion is done automatically?
Explicit
Implicit
Manual
Casting only
What is the result of 10 / 3 in integer division?
A) 3.33
B) 3
C) 4
D) Error
What is the value of x after int x = 5; x += 2 * 3;?
A) 11
B) 21
C) 7
D) 17
Which operator has highest precedence?
+
=
*
++ (postfix)
What does == do?
Assigns value
Compares values
Checks address
None
What is the output of: int a = 1; cout << a++ << endl;
A) 1
B) 2
C) 0
D) Error
Which statement is TRUE about if?
It must have an else
Condition must be in parentheses
It ends with semicolon
It cannot be nested
What will this print? int x = 5; if (x = 3) cout << "Yes"; else cout << "No";
Yes
No
Error
Nothing
The switch statement works with:
float
string (C++11+)
char
Both B and C
Which is equivalent to if (a > b)?
a < b
a == b
!(a <= b)
!(a >= b)
How many times will this loop run? for(int i=0; i<5; i++);
5
4
0
1
while loop checks condition:
Before execution
After execution
Randomly
Only once
Which loop runs at least once?
for
while
do-while
None
What does break do?
Skips current iteration
Stops entire loop
Ends program
Goes to next iteration
What is wrong here? for(int i=0; i<10; i--)
Syntax error
Infinite loop
Runs 10 times
Skips all
What is the correct syntax of a function definition?
A) returnType functionName(parameters) {}
B) functionName returnType(parameters) {}
C) returnType(parameters) functionName {}
D) functionName(parameters) returnType {}
What is a parameter?
Value inside function call
Value inside function definition
Return type
Local variable
What is function overloading?
Using too many functions
Same name, different parameters
Same parameters, different names
Functions inside functions
What will this return? int fun() { int x = 10; return x; }
Nothing
0
10
Error
Arrays in C++ are:
Fixed size
Dynamic
Changeable at runtime
Unlimited
What is the index of the first element?
-1
0
1
Depends
Which correctly declares a string?
char name[10];
string name;
Both A and B
int name;
What does int *p; mean?
p stores an integer
p is a pointer to an integer
p is an array
p is a function
If int a = 5; int *p = &a; what is *p?
Address of a
Value 5
Pointer itself
Error
What is the output? int a = 5, b = 10; if (a < b && b > 5) cout << "True"; else cout << "False";
True
False
Error
No output
