https://www.sanfoundry.
com/
https://www.sanfoundry.com/cplusplus-interview-questions-answers/
1. What is the size of wchar_t in C++?
a) 2
b) 4
c) 2 or 4
d) Based on the number of bits in the system
2. Pick the odd one out
a) array type
b) character type
c) boolean type
d) integer type
3. Which data type is used to represent the absence of parameters?
a) int
b) short
c) void
d) float
4. What does an escape code represent?
a) alert
b) backslash
c) tab
d) form feed
5. Which type is best suited to represent the logical values?
a) integer
b) boolean
c) character
d) all of the mentioned
6. Identify the user-defined types from the following?
a) enumeration
b) classes
c) both enumeration and classes
d) int
7. Which of the following statements are true?
int f(float)
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
8. The value 132.54 can be represented using which data type?
a) double
b) void
c) int
d) bool
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
10. Pick the odd one out.
a) integer, character, boolean, floating
b) enumeration, classes
c) integer, enum, void
d) arrays, pointer, classes
11. The constants are also called as
a) const
b) preprocessor
c) literals
d) none of the mentioned
12. What are the parts of the literal constants?
a) integer numerals
b) floating-point numerals
c) strings and boolean values
d) all of the mentioned
13. How are the constants declared?
a) const keyword
b) #define preprocessor
c) both const keyword and #define preprocessor
d) none of the mentioned
14. What is the output of this program?
#include <iostream>
using namespace std;
int main()
int const p = 5;
cout << ++p;
return 0;
a) 5
b) 6
c) Error
d) None of the mentioned
15. What is the output of this program?
#include <iostream>
using namespace std;
#define PI 3.14159
int main ()
float r = 2;
float circle;
circle = 2 * PI * r;
cout << circle;
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
17. Regarding the following statement which of the statements is true?
const int a = 100;
a) Declares a variable a with 100 as its initial value
b) Declares a construction a with 100 as its initial value
c) Declares a constant a whose value will be 100
d) Constructs an integer type variable with an as identifier and 100 as the value
18. The difference between x and ‘x’ is
a) The first one refers to a variable whose identifier is x and the second one refers to the
character constant x
b) The first one is a character constant x and the second one is the string literal x
c) Both are same
d) None of the mentioned
19. How to declare a wide character in the string literal?
a) L prefix
b) l prefix
c) W prefix
d) none of the mentioned
20. Which of the following will not return a value?
a) null
b) void
c) empty
d) free
21. Which of the following correctly declares an array?
a) int array[10];
b) int array;
c) array{10};
d) array array[10];
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
23. What is a array?
a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same type placed in non-contiguous memory locations
d) None of the mentioned
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;
26. What will be the output of this program?
#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++)
result += array1[temp];
for (temp = 0; temp < 4; temp++)
result += array2[temp];
cout << result;
return 0;
a) 6553
b) 6533
c) 6522
d) 12200
27. What will be the output of the this program?
#include <stdio.h>
using namespace std;
int main ()
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++) {
result += array[n];
}
cout << result;
return 0;
a) 25
b) 26
c) 27
d) None of the mentioned
28. What is the output of this program?
#include <stdio.h>
using namespace std;
int main()
int a = 5, b = 10, c = 15;
int arr[3] = {&a, &b, &c};
cout << *arr[*arr[1] - 8];
return 0;
a) 15
b) 18
c) garbage value
d) compile time error
29. What is the output of this program?
#include <stdio.h>
using namespace std;
int main()
{
char str[5] = "ABC";
cout << str[3];
cout << str;
return 0;
a) ABC
b) ABCD
c) AB
d) None of the mentioned
$ g++ array.cpp
$ a.out
ABC
30. What is the output of this program?
#include <stdio.h>
using namespace std;
int main()
int array[] = {10, 20, 30};
cout << -2[array];
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
33. What is a array?
a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same type placed in non-contiguous memory locations
d) None of the mentioned
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;
36. What will be the output of this program?
#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
for (temp = 0; temp < 5; temp++)
result += array1[temp];
for (temp = 0; temp < 4; temp++)
result += array2[temp];
cout << result;
return 0;
a) 6553
b) 6533
c) 6522
d) 12200
37. What will be the output of the this program?
#include <stdio.h>
using namespace std;
int main ()
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++) {
result += array[n];
cout << result;
return 0;
a) 25
b) 26
c) 27
d) None of the mentioned
38. What is the output of this program?
#include <stdio.h>
using namespace std;
int main()
int a = 5, b = 10, c = 15;
int arr[3] = {&a, &b, &c};
cout << *arr[*arr[1] - 8];
return 0;
a) 15
b) 18
c) garbage value
d) compile time error
39. What is the output of this program?
#include <stdio.h>
using namespace std;
int main()
char str[5] = "ABC";
cout << str[3];
cout << str;
return 0;
a) ABC
b) ABCD
c) AB
d) None of the mentioned
View Answer
40. What is the output of this program?
#include <stdio.h>
using namespace std;
int main()
int array[] = {10, 20, 30};
cout << -2[array];
return 0;
a) -15
b) -30
c) compile time error
d) garbage value
41. Choose the correct option.
extern int i;
int i;
a) both 1 and 2 declare i
b) 1 declares the variable i and 2 defines i
c) 1 declares and defines i, 2 declares i
d) 1 declares i,2 declares and defines i
42. Pick the right option
Statement 1:A definition is also a declaration.
Statement 2:An identifier can be declared just once.
a) Statement 1 is true, Statement 2 is false
b) Statement 2 is true, Statement 1 is false
c) Both are false
d) Both are true
Answer: b
43. Which of the given statements are false.
1. extern int func;
2. extern int func2(int,int);
3. int func2(int,int);
4. extern class foo;
a) 3 and 4 only
b) 2 and 3 only
c) only 4
d) 2, 3 and 4
44. Pick the right option
Statement 1:Global values are not initialized by the stream.
Statement 2:Local values are implicitly initialised to 0.
a) Statement 1 is true, Statement 2 is false
b) Statement 2 is true, Statement 1 is false
c) Both are false
d) Both are true
45. What is the output of this program?
#include <iostream>
using namespace std;
int g = 100;
int main()
int a;
int b;
b = 20;
a = 35;
g = 65;
cout << b << a << g;
a = 50;
cout << a << g;
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
47. What is the output of this program?
#include <iostream>
using namespace std;
void addprint()
static int s = 1;
s++;
cout << s;
int main()
addprint();
addprint();
addprint();
return 0;
a) 234
b) 111
c) 123
d) 235
48. What is the output of this program?
#include <iostream>
using namespace std;
int main()
int a = 10;
if (a < 10) {
for (i = 0; i < 10; i++)
cout << i;
else {
cout << i;
return 0;
a) 0123456789
b) 123456789
c) 0
d) error
49. Identify the incorrect statements.
int var = 10;
int *ptr = &(var + 1); //statement 1
int *ptr2 = &var; //statement 2
&&var = 40; //statement 3
a) Statement 1 and 2 are wrong
b) Statement 2 and 3 are wrong
c) Statement 1 and 3 are wrong
d) All the three are wrong
50. Identify the type of the variables.
typedef char* CHAR;
CHAR p,q;
a) char*
b) char
c) CHAR
d) unknown
51. Choose the correct option.
extern int i;
int i;
a) both 1 and 2 declare i
b) 1 declares the variable i and 2 defines i
c) 1 declares and defines i, 2 declares i
d) 1 declares i,2 declares and defines i
52. Pick the right option
Statement 1:A definition is also a declaration.
Statement 2:An identifier can be declared just once.
a) Statement 1 is true, Statement 2 is false
b) Statement 2 is true, Statement 1 is false
c) Both are false
d) Both are true
Answer: b
53. Which of the given statements are false.
1. extern int func;
2. extern int func2(int,int);
3. int func2(int,int);
4. extern class foo;
a) 3 and 4 only
b) 2 and 3 only
c) only 4
d) 2, 3 and 4
54. Pick the right option
Statement 1:Global values are not initialized by the stream.
Statement 2:Local values are implicitly initialised to 0.
a) Statement 1 is true, Statement 2 is false
b) Statement 2 is true, Statement 1 is false
c) Both are false
d) Both are true
55. What is the output of this program?
#include <iostream>
using namespace std;
int g = 100;
int main()
int a;
int b;
b = 20;
a = 35;
g = 65;
cout << b << a << g;
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
57. What is the output of this program?
#include <iostream>
using namespace std;
void addprint()
static int s = 1;
s++;
cout << s;
int main()
addprint();
addprint();
addprint();
return 0;
a) 234
b) 111
c) 123
d) 235
58. What is the output of this program?
#include <iostream>
using namespace std;
int main()
int a = 10;
if (a < 10) {
for (i = 0; i < 10; i++)
cout << i;
else {
cout << i;
return 0;
a) 0123456789
b) 123456789
c) 0
d) error
59. Identify the incorrect statements.
int var = 10;
int *ptr = &(var + 1); //statement 1
int *ptr2 = &var; //statement 2
&&var = 40; //statement 3
a) Statement 1 and 2 are wrong
b) Statement 2 and 3 are wrong
c) Statement 1 and 3 are wrong
d) All the three are wrong
60. Identify the type of the variables.
typedef char* CHAR;
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
62. Which of the following is a valid floating-point literal?
a) f287.333
b) F287.333
c) 287.e2
d) 287.3.e2
63. What is the range of the floating point numbers?
a) -3.4E+38 to +3.4E+38
b) -3.4E+38 to +3.4E+34
c) -3.4E+38 to +3.4E+36
d) -3.4E+38 to +3.4E+32
64. Which of three sizes of floating point types should be used when extended precision is
required?
a) float
b) double
c) long double
d) extended float
65. What is the output of this program?
#include <iostream>
using namespace std;
int main()
float num1 = 1.1;
double num2 = 1.1;
if (num1 == num2)
cout << "stanford";
else
cout << "harvard";
return 0;
a) harvard
b) stanford
c) compile time error
d) runtime error
66. What is the output of this program?
#include <iomanip>
#include <iostream>
using namespace std;
int main()
cout << setprecision(17);
double d = 0.1;
cout << d << endl;
return 0;
a) 0.11
b) 0.10000000000000001
c) 0.100001
d) compile time error
67. What is the output of the following program?
advertisement
#include <iostream>
using namespace std;
int main()
float i = 123.0f;
cout << i << endl;
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
69. What is the output of this program?
#include <iostream>
using namespace std;
int main()
float f1 = 0.5;
double f2 = 0.5;
if (f1 == 0.5f)
cout << "equal";
else
cout << "not equal";
return 0;
a) equal
b) not equal
c) compile time error
d) runtime error
70. Which is correct with respect to size of the data types?
a) char > int < float
b) int < char > float
c) char < int < float
d) char < int < double
71. The size_t integer type in C++ is?
a) Unsigned integer of at least 64 bits
b) Signed integer of at least 16 bits
c) Unsigned integer of at least 16 bits
d) Signed integer of at least 64 bits
72. What is the output of the following program?
#include <iostream>
using namespace std;
int main()
int x = -1;
unsigned int y = 2;
if(x > y)
cout << "x is greater";
else
cout << "y is greater";
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
78. What will be the output of this program?
#include <iostream>
using namespace std;
int main()
int a = 8;
cout << "ANDing integer 'a' with 'true' :" << a && true;
return 0;
a) ANDing integer ‘a’ with ‘true’ :8
b) ANDing integer ‘a’ with ‘true’ :0
c) ANDing integer ‘a’ with ‘true’ :1
d) None of the mentioned
79. What will be output of this program?
#include <iostream>
using namespace std;
int main()
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << k;
return 0;
a) compile time error
b) -1 1
c) 1 -1
d) implementation defined
80. What will be output of this function?
int main()
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
a) 0
b) 1
c) Compiler error may be possible
d) Runtime error may be possible
81. How many characters are specified in the ASCII scheme?
a) 64
b) 128
c) 256
d) 82. Select the right option.
Given the variables p, q are of char type and r, s, t are of int type
1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);
a) 1 is true but 2 is false
b) 1 is false and 2 is true
c) both 1 and 2 are true
d) both 1 and 2 are false
83. Which of the following belongs to the set of character types?
a) char
b) wchar_t
c) only a
d) both wchar_t and char
84. What will be the output of this program?
#include <iostream>
using namespace std;
int main()
char c = 74;
cout << c;
return 0;
a) A
b) N
c) J
d) I
85. How do we represent a wide character of the form wchar_t?
a) L’a’
b) l’a’
c) L[a].
d) la
86. What is the output of this program?
#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.
88. Is the size of character literals different in C and C++?
a) Implementation defined
b) Can’t say
c) Yes, they are different
d) No, they are not different
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
92. What will be used when terminating a structure?
a) :
b) }
c) ;
d) ;;
93. What will happen when the structure is declared?
a) it will not allocate any memory
b) it will allocate the memory
c) it will be declared and initialized
d) none of the mentioned
94. The declaration of the structure is also called as?
a) structure creator
b) structure signifier
c) structure specifier
d) none of the mentioned
95. What is the output of this program?
#include <iostream>
#include <string.h>
using namespace std;
int main()
struct student
int num;
char name[25];
};
student stu;
stu.num = 123;
strcpy(stu.name, "John");
cout << stu.num << endl;
cout << stu.name << endl;
return 0;
a) 123
john
b) john
john
c) compile time error
d) none of the mentioned
96. What is the output of this program?
#include <iostream>
using namespace std;
struct Time
int hours;
int minutes;
int seconds;
};
int toSeconds(Time now);
int main()
Time t;
t.hours = 5;
t.minutes = 30;
t.seconds = 45;
cout << "Total seconds: " << toSeconds(t) << endl;
return 0;
int toSeconds(Time now)
return 3600 * now.hours + 60 * now.minutes + now.seconds;
a) 19845
b) 20000
c) 15000
d) 19844
97. What will be the output of this program?
advertisement
#include <iostream>
using namespace std;
int main()
struct ShoeType
string style;
double price;
};
ShoeType shoe1, shoe2;
shoe1.style = "Adidas";
shoe1.price = 9.99;
cout << shoe1.style << " $ "<< shoe1.price;
shoe2 = shoe1;
shoe2.price = shoe2.price / 9;
cout << shoe2.style << " $ "<< shoe2.price;
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
98. What is the output of this program?
#include <iostream>
using namespace std;
struct sec
int a;
char b;
};
int main()
struct sec s ={25,50};
struct sec *ps =(struct sec *)&s;
cout << ps->a << ps->b;
return 0;
}
a) 252
b) 253
c) 254
d) 262
99. Which of the following is a properly defined structure?
a) struct {int a;}
b) struct a_struct {int a;}
c) struct a_struct int a;
d) struct a_struct {int a;};
100. Which of the following accesses a variable in structure *b?
a) b->var;
b) b.var;
c) b-var;
d) b>var;