Font size
WorksheetsC C++ Final Test 20-APR-2022
Total questions: 78
Worksheet time: 54mins
Which of the following are themselves a collection of different data types?
String
Struct
char
all
Which operator connects the structure name to its member name?
-
=
.
>>
Which of the following cannot be a structure member?
another structure
array
Function
None
What is the output of this C code?
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
s.no = 8;
printf("%d", s.no);
}
Nothing
Compile error
8
Junk
Size of a union is determined by size of the.
First member in the union
Last member in the union
C. Biggest member in the union
Sum of the sizes of all members
What will be the output
Name:
Subject:
Percentage: 86.50000
Name:Raju
Subject:
Percentage: 86.50000
Name: Raju
Subject: Maths
Percentage: 86.50000
Error
Memory allocated for structure members are always contigious
True
False
What do you understand by:
void update(struct student *s);
update is a function that takes an argument as pointer to structure variable and returns nothing
update is a method that takes structure type variable as parameter
Error, we cannot pass structure variable as pointer to a function
update takes pointer argument but it cannot return void
Local variables are stored in an area called____________
Heap
Permanent storage area
Stack
Free memory
The size of both stack and heap remains the same during run time.
True
False
What is the return type of malloc() or calloc()?
Pointer of allocated memory type
void**
void*
int*
The expression:
int *p = new int[20];
allocates 20 integers and assigns the base address to p
allocates 20 integers off the stack local to a block
reads in 20 integer values from cin
allocates an integer of size 20 bytes
What does the variable i contain after the following code executes?
int i = 17;
int *p = &i;
*p = 98;
98
17
81
0
Every byte in the computer's memory is assigned a unique:
pointer
address
dynamic allocation
name
If a variable uses more than one byte of memory, for pointer purposes its address is:
the address of the last byte of storage
the average of all the addresses used to store that variable
the address of the first byte of storage
the address of the second byte of storage
The __________, also known as the address operator, returns the memory address of a variable.
asterisk (* )
ampersand ( & )
percent sign ( % )
exclamation point ( ! )
What does the following statement do?
double *num2;
Declares a double variable named num2
Declares and initializes a pointer variable named num2
Initializes a pointer variable named num2
Declares a pointer variable named num2
A pointer variable is designed to store
any legal C++ value
only floating-point values
an integer
a memory address
Dynamic memory allocation occurs
when a new variable is created by the compiler
when a new variable is created at runtime
when a pointer fails to dereference the right variable
when a pointer is assigned an incorrect address
What is the output of following program?
20
30
Compile Error
Runtime Error
Arrays always occupy contiguous memory area
True
False
Which of the following format specifier in printf is used to print pointers?
%c
%d
%f
%p
A pointer is
A keyword used to create variables
A variable that stores address of an instruction
A variable that stores address of a varaibe
All of the above
What is the & in pointers?
Dereferences the memory address into an object
References an object into a memory address
Makes a new copy of the object as a memory address
None of the above.
How do you make a pointer point to an existing variable?
int y = 0;
int *x = y;
int x = y;
int *x = &y;
int &x = *y;
The process of defining a problem (or the solution to a problem) in terms of (a simpler version of) itself is known as:
repetition
recursion
reapparition
reversing
Which of the following is the best definition of a recursive method?
A method that iterates itself exactly 5 times.
A method that invokes itself by name within the method.
A method that will never iterate infinitely.
A method that cannot be called more than once.
Recursion is similar to which of the following?
if-else
switch-case
loops
none of the above
The following function finds the factorial of any number
int factorial(int n)
{
if(n == 0 || n == 1) return 1;
return n * factorial(n-1);
}
What would calling factorial(4) output?
24
16
8
64
The following function finds the factorial of any number
int factorial(int n)
{
if(n == 0 || n == 1) return 1;
return n * factorial(n-1);
}
What would calling factorial(2) output?
12
2
0
22
Make the following function return the following number in the fibonacci sequence
int fibo(int n)
{
if(n == 0 || n == 1) return n;
return _________________;
}
fib (n-1)+fib (n-2)
fibo(n-1)+fibo(n-2)
fibo(n*2)
fibo(n+1)+fibo(n+2)
2. Which statement best describes logic errors?
An error in a program that causes it to produce incorrect ouputs but not a crash.
An error in a program that causes it to crash.
An error in the program caused by mis-spelt instructions.
An error in a program caused by hardware failure.
6.Find error/ output in following code
How many times " placement Questions" will print.
int main
{
int x;
for ( x=1;x <=10; x++)
{
if ( x < 5)
Continue;
else
break;
Printf (" placement Question ");
{
return 0;
}
Infinite time
11 times
0 time
10 times
11.Is there any limit in adding no of header files in program?
yes
no
14.what will be the output?
#include <stdio.h>
void decrement();
int main()
{
decrement();
decrement();
decrement();
return 0;
}
void decrement()
{
int i = 5;
printf("%d",i);
i--;
}
A) 555
(B) 543
(C) 545
(D) 544
The Parameter list in main function represent ------- parameter
formal parameter
argument list
actual parameter
above all
A function declaration is also known as function ----------
prototype
call
definition
above all
int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;
printf("%d",z);
12
16
20
0
Which of the following comments about the ++ operator are correct?
1) It is a unary operator
2) The operand can come before or after the operator
3)It associates from the right
1 and 3
1 and 2
2 and 3
1,2,3
Which operator has the lowest priority?
++
%
+
||
int main()
{
int a = 25%10;
printf("%d", a);
return 0;
}
5
2
2.5
5.5
The modulus operator (%) can be used only with integers.
True
False
!= is the example of ____________________ operator.
Relational
Logical
Assignment
Conditional
The _____________ operator checks if the value of left operand is greater than the value of right operand.
= =
<
>
=
#include <stdio.h>
int main()
{
int i = 95;
char c = 97;
printf("%d, %d\n", sizeof(i), sizeof(c));
return 0;
}
2,1
4,2
2,4
2,8
#include <stdio.h>
void main()
{
int x = 5 * 9 / 3 + 9;
}
24
3
23
4
What is the output of C Program.?
int main()
{
int a[] = {1,2,3,4};
int b[4] = {5,6,7,8};
printf("%d,%d", a[0], b[0]);
}
1
2
4
Error
What is the output of C Program.?
int main() {
int a[] = {1,2,3,4};
int b[4] = {5,6,7,8};
printf("%d,%d", a[0], b[0]);
}
1,5
2,6
0,0
Error
What is the output of C Program.?
int main() {
int a[3] = {10,12,14};
a[1]=20;
int i=0;
while(i<3)
{ printf("%d ", a[i]);
i++; }
}
20 12 14
10 20 14
10 12 20
Error
What is the output of C program.?
int main() {
int a[3] = {10,12,14};
int i=0;
while(i<3)
{ printf("%d ", i[a]);
i++; }
}
14 12 10
10 10 10
10 12 14
None
Which of the following is a correct comment?
*/ Comments */
** Comment **
/* Comment */
{ Comment }
Program
int main()
{
cout<<"Hi everybody";
return 0;
}
Which of the following is NOT a comparison operator in C++ language?
>
<=
=
==
Evaluate the following expressions to true or false
3!=4-1
true
False
Evaluate the following expressions to true or false
5 >= (1+6)-4
True
False
Evaluate the following expressions to true or false
5+1==6 || 8-1>4
True
False
If originally x=2,y=0, and z=1, what is the value of x, y, and z after executing the following code?
if (x>y)
y=x;
else
z=x;
x=2 y=2 z=1
x=0 y=2 z=0
x=2 y=1 z=1
x=2 y=0 z=1
Each pass through a loop is called a/an
pass through
enumeration
iteration
culmination
In a group of nested loops, which loop is executed the most number of times?
the outermost loop
the innermost loop
all loops are executed the same number of times
cannot be determined without knowing the size of the loops
The statement i++; is equivalent to
i = i + i;
i = i + 1;
i = i - 1;
i --;
What's wrong? for (int k = 2, k <=12, k++)
the increment should always be ++k
the variable must always be the letter i when using a for loop
there should be a semicolon at the end of the statement
the commas should be semicolons
C Language is a successor to which language.?
FORTRAN
D Language
BASIC
B Language
C language was invented in which laboratories.?
Uniliver Labs
IBM Labs
AT&T Bell Labs
Verizon Labs
A C program is a combination of.?
Statements
Function
variables
all
An Identifier may contain.?
Letters a-z, A-Z in Basic character set.
Unicode alphabet characters other languages
Underscore _ symbol
Numbers 0 to 9
Unicode Numbers in other languages
All the above
Choose correct statements
A constant value does not change.
A variable value can change according to needs.
A constant can change its values.
A variable can have one constant value only.
There is no restriction on number of values for constants or variables.
Constants and Variables can not be used in a singe main function.
Find an integer constant.
3.145
34
"125"
None of the above
y = 3;
x = 5 * y;
After running the following code, what will be the value of apples?
apples = 3;
apples++;
4
5
3
0
What will this code output?
int banana = 3;
banana += 5;
cout<<banana;
3
5
8
15
Which of these variables can contain decimal numbers?
int apples;
double apples;
char apples;
void apples;
What is the alternative for x = x + 5?
x += 5;
x -= 4;
x = y + 5;
x=+5
What is the alternative for y = y * 2?
y = * 2;
y*= 2
y **;
x=+2;
How can we store a user input to the variable
int apples; ?
cin << int apples;
cin >> apples;
cin;
What will this code output?
int apples = 3;
int bananas = apples * 2;
cout<<banana << "," <<apples;
3, 6
3, 3
6, 3
6, 6
