Summative Questions
Summative Questions
com/
https://www.sanfoundry.com/cplusplus-interview-questions-answers/
a) f is a function taking an argument of type int and returning a floating point number
b) f is a function taking an argument of type float and returning an integer
c) f is a function of type float
d) none of the mentioned
9. When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible
#include <iostream>
int main()
int const p = 5;
return 0;
a) 5
b) 6
c) Error
d) None of the mentioned
#include <iostream>
#define PI 3.14159
int main ()
float r = 2;
float circle;
circle = 2 * PI * r;
return 0;
}
a) 12.5664
b) 13.5664
c) 10
d) compile time error
16. Which of the following statement is not true about preprocessor directives?
a) These are lines read and processed by the preprocessor
b) They do not produce any code by themselves
c) These must be written on their own line
d) They end with a semicolon
22. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
24. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;
25. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
#include <stdio.h>
int main()
{
result += array1[temp];
result += array2[temp];
return 0;
a) 6553
b) 6533
c) 6522
d) 12200
#include <stdio.h>
int main ()
int n, result = 0;
result += array[n];
}
return 0;
a) 25
b) 26
c) 27
d) None of the mentioned
#include <stdio.h>
int main()
return 0;
a) 15
b) 18
c) garbage value
d) compile time error
#include <stdio.h>
int main()
{
return 0;
a) ABC
b) ABCD
c) AB
d) None of the mentioned
$ g++ array.cpp
$ a.out
ABC
#include <stdio.h>
int main()
return 0;
a) -15
b) -30
c) compile time error
d) garbage value
31. Which of the following correctly declares an array?
a) int array[10];
b) int array;
c) array{10};
d) array array[10];
32. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
34. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;
35. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
#include <stdio.h>
int main()
result += array1[temp];
result += array2[temp];
return 0;
a) 6553
b) 6533
c) 6522
d) 12200
#include <stdio.h>
int main ()
result += array[n];
return 0;
a) 25
b) 26
c) 27
d) None of the mentioned
#include <stdio.h>
int main()
return 0;
a) 15
b) 18
c) garbage value
d) compile time error
int main()
return 0;
a) ABC
b) ABCD
c) AB
d) None of the mentioned
View Answer
#include <stdio.h>
int main()
return 0;
a) -15
b) -30
c) compile time error
d) garbage value
41. Choose the correct option.
extern int i;
int i;
a) 3 and 4 only
b) 2 and 3 only
c) only 4
d) 2, 3 and 4
#include <iostream>
int g = 100;
int main()
int a;
int b;
b = 20;
a = 35;
g = 65;
a = 50;
return 0;
a) 2035655065
b) 2035655035
c) 2035635065
d) none of the mentioned
46. Can two functions declare variables(non static) with the same name.
a) No
b) Yes
c) Yes, but not a very efficient way to write programs
d) No, it gives a runtime error
#include <iostream>
void addprint()
static int s = 1;
s++;
cout << s;
int main()
addprint();
addprint();
addprint();
return 0;
a) 234
b) 111
c) 123
d) 235
#include <iostream>
using namespace std;
int main()
int a = 10;
if (a < 10) {
cout << i;
else {
cout << i;
return 0;
a) 0123456789
b) 123456789
c) 0
d) error
CHAR p,q;
a) char*
b) char
c) CHAR
d) unknown
extern int i;
int i;
a) 3 and 4 only
b) 2 and 3 only
c) only 4
d) 2, 3 and 4
#include <iostream>
int g = 100;
int main()
int a;
int b;
b = 20;
a = 35;
g = 65;
a = 50;
cout << a << g;
return 0;
a) 2035655065
b) 2035655035
c) 2035635065
d) none of the mentioned
56. Can two functions declare variables(non static) with the same name.
a) No
b) Yes
c) Yes, but not a very efficient way to write programs
d) No, it gives a runtime error
#include <iostream>
void addprint()
static int s = 1;
s++;
cout << s;
int main()
addprint();
addprint();
addprint();
return 0;
a) 234
b) 111
c) 123
d) 235
#include <iostream>
int main()
int a = 10;
if (a < 10) {
cout << i;
else {
cout << i;
return 0;
a) 0123456789
b) 123456789
c) 0
d) error
CHAR p,q;
a) char*
b) char
c) CHAR
d) unknown
61. Which of the following is not one of the sizes of the floating point types?
a) short float
b) float
c) long double
d) double
#include <iostream>
int main()
if (num1 == num2)
else
return 0;
a) harvard
b) stanford
c) compile time error
d) runtime error
#include <iomanip>
#include <iostream>
double d = 0.1;
return 0;
a) 0.11
b) 0.10000000000000001
c) 0.100001
d) compile time error
advertisement
#include <iostream>
int main()
float i = 123.0f;
return 0;
a) 123.00
b) 1.23
c) 123
d) compile time error
123
68. Which is used to indicate single precision value?
a) F or f
b) L or l
c) Either F or for L or l
d) Neither F or for L or l
#include <iostream>
int main()
float f1 = 0.5;
double f2 = 0.5;
if (f1 == 0.5f)
else
return 0;
a) equal
b) not equal
c) compile time error
d) runtime error
#include <iostream>
int main()
int x = -1;
unsigned int y = 2;
if(x > y)
else
a) x is greater
b) y is greater
c) implementation defined
d) arbitrary
73. Which of these expressions will return true if the input integer v is a power of two?
a) (v | (v + 1)) == 0;
b) (~v & (v – 1)) == 0;
c) (v | (v – 1)) == 0;
d) (v & (v – 1)) == 0;
74. What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7;
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined
75. Which of these expressions will make the rightmost set bit zero in an input integer x?
a) x = x | (x-1)
b) x = x & (x-1)
c) x = x | (x+1)
d) x = x & (x+1)
76. Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)
77. 0946, 786427373824, ‘x’ and 0X2f are _____ _____ ____ and _____ literals respectively.
a) decimal, character,octal, hexadecimal
b) octal, hexadecimal, character, decimal
c) hexadecimal, octal, decimal, character
d) octal, decimal, character, hexadecimal
#include <iostream>
int a = 8;
cout << "ANDing integer 'a' with 'true' :" << a && true;
return 0;
#include <iostream>
int main()
int i = 3;
int l = i / -2;
int k = i % -2;
return 0;
register int i = 1;
return 0;
a) 0
b) 1
c) Compiler error may be possible
d) Runtime error may be possible
#include <iostream>
char c = 74;
cout << c;
return 0;
a) A
b) N
c) J
d) I
#include <stdio.h>
int main()
char a = '\012';
printf("%d", a);
return 0;
a) Compiler error
b) 12
c) 10
d) Empty
87. In C++, what is the sign of character data type by default?
a) Signed
b) Unsigned
c) Implementation dependent
d) None of the mentioned
Answer: c
Explanation: The standard does not specify if plain char is signed or unsigned. There are
three distinct character types according to the standard: char, signed char and unsigned
char.
89. Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char)
return?
a) 4
b) 1
c) Implementation dependent
d) Machine dependent
90. What constant defined in <climits> header returns the number of bits in a char?
a) CHAR_SIZE
b) SIZE_CHAR
c) BIT_CHAR
d) CHAR_BIT
91. The data elements in the structure are also known as what?
a) objects
b) members
c) data
d) none of the mentioned
#include <iostream>
#include <string.h>
int main()
struct student
int num;
char name[25];
};
student stu;
stu.num = 123;
strcpy(stu.name, "John");
return 0;
a) 123
john
b) john
john
c) compile time error
d) none of the mentioned
#include <iostream>
struct Time
int hours;
int minutes;
int seconds;
};
int main()
Time t;
t.hours = 5;
t.minutes = 30;
t.seconds = 45;
a) 19845
b) 20000
c) 15000
d) 19844
advertisement
#include <iostream>
int main()
struct ShoeType
string style;
double price;
};
shoe1.style = "Adidas";
shoe1.price = 9.99;
shoe2.price = shoe2.price / 9;
return 0;
a) Adidas $ 9.99
Adidas $ 1.11
b) Adidas $ 9.99
Adidas $ 9.11
c) Adidas $ 9.99
Adidas $ 11.11
d) none of the mentioned
#include <iostream>
struct sec
int a;
char b;
};
int main()
return 0;
}
a) 252
b) 253
c) 254
d) 262