WorksheetsC Programming Quiz
Total questions: 33
Worksheet time: 19mins
What is the return type of the function with prototype float func(char x, float v, double t);
double
char
string
int
float
Which of the following accesses a variable in structure b?
b.var;
b=var;
b->var;
How many times the current loop will execute? for (int i = 0; i <= 5; i += 3);
1 time
5 times
2 times
3 times
4 times
What is the correct value to return to the operating system upon successful completion of a program?
10
-1
20
0
1
Which of the following gives the value stored at the address pointed to by the pointer gala?
*gala
gala[0]
&gala
gala
When following code is executed, what value will be in variable b? b = 5; a = b++;
5
4
0
6
3
Write correct function prototype for the function intToDouble that takes an integer argument number and returns a double.
int intToDouble(number);
double intToDouble(double number);
float intToDouble(int number);
double intToDouble(int number);
Pointers may be compared by using relational operators.
False
True
By default, all the files are opened in _____ mode.
binary
text
When following code is executed, what value will be in variable a? b = 5; a = b++;
5
1
0
7
6
What will be used when terminating a structure?
Semicolon
Dot
Colon
Brackets
How many times the current loop will execute? for (int i = 0; i <= 5; i += 3);
5 times
1 time
2 times
4 times
3 times
What is the difference between array and structure?
No difference
Structure can include members of different data types
Arrays can include only integers
Write correct function prototype for the function intToDouble that takes an integer argument number and returns a double.
double intToDouble(double number);
float intToDouble(int number);
int intToDouble(number);
double intToDouble(int number);
What is the correct value to return to the operating system upon successful completion of a program?
20
1
0
10
-1
Which of the following is a complete function?
funct(int x)
funct;
funct();
int funct(int x) { return x = x + 1; }
We declare a function with _____ if it does not have any return type.
int
char
float
void
Which of the following is the proper declaration of a pointer x?
int &x;
int x;
int *x;
ptr x;
Choose the right option: string* x; string y;
both x and y are pointer to string types
x is a pointer to a string, y is a string
y is a pointer to a string, x is a string
Write a statement to initialize an array with values 1,2,3,4,5
int myArray[]={1,2,3,4,5};
int myArray[5]=1,2,3,4,5;
int myArray(1,2,3,4,5);
int myArray[]={1,2,3,4,5}
This loop executes the code block once before checking condition.
for
while
do while
Difference between while and do-while loop:
while checks condition before loop, do-while after
do checks condition before first iteration
In C++, this statement terminates the loop when encountered.
&&
continue
break
(3<5) || (7>8)
true
false
How do you open a file for writing in C++?
ifstream file("filename.txt");
file.open("filename.txt");
fstream file("filename.txt");
ofstream file("filename.txt");
What happens if you write to a file opened in read mode?
creates new file
overwrites file
throws an error
writes without issues
What is an array?
same type, non-contiguous
series of elements
none
same type, contiguous memory
Evaluate !(1 && !(0 || 1))
true
false
How many times loop executes? for(int i=1;i<=4;i+=3);
1
2
4
0
3
The set of instructions a computer follows is called:
program
memory
type
line
variable
Correct operator to compare two variables:
==
+=
&&
||
Equal
Evaluate !(1 && !(0 || 1))
false
true
Difference between while and do-while:
