You are on page 1of 12

1. Which of the following is used for comments in C++?

A. /* comment */
B. // comment */
C. // comment
D. both // comment or /*
comment */
2. Which of the following is a correct identifier in C++?
A. VAR_1234 C. 7VARNAME
B. $var_name D. 7var_name
3. Given the following block of code. Which line contains an error?
1. int aa = 5;
2. int bc = 9 9;
3. int c1 = 3 2;
4. int d_ = 7;
A. Line 1 D. Line 4
B. Line 2 E. There are no errors
C. Line 3
4. Given the following block of code. Which line contains an error?
1. int m = 5;
2. double n = 9 9;
3. double o = m ;
4. int p = n ;
A. Line 1 D. Line 4
B. Line 2 E. There are no errors
C. Line 3
5. What result is printed by this block of code?

int i = 2 3;
int j = 7;
int k = i % j ;
cout<< ”The r e s u l t i s :”;
cout<k;
A. 0 C. 7
B. 2 D. There is an error

1|Page
E. Answer not shown
6. What happens if the following program is executed in C and C++?

#include <stdio.h>
void func(void)
{
printf("Hello");
}
void main()
{
func();
func(2);
}

A. Outputs Hello once C. Successful execution


B. Outputs Hello twice D. Error
7. Which of the following correctly declares an array in C++?
A. array{10};
B. array array[10];
C. int array;
D. int array[10];
8. Which of the following is used to terminate the function declaration in C++?
A. ; C. )
B. ] D. :
9. Which of the following symbol is used to declare the pre-processor directives in C++?
A. $ C. #
B. ^ D. *
10. What will be the output of the following C++ code?

#include <stdio.h>
#include<iostream>
using namespace std;
int main ()

2|Page
{
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. 21
B. 27
C. 26
D. 25
11. Keywords are also called
A. Preprocessors
B. Reserved words
C. Punctuation marks
D. Operators
12. Overflow is a one kind of
A. Syntax error
B. Logical error
C. Run time error
D. None of them
13. In C++ a name that is assigned by a user for a program elements such as variable,
type, class, function or namespaces is called
A. Operators
B. Identifiers
C. Literals
D. All of them
14. Unsigned integers in C++ are
3|Page
A. Negative numbers
B. Non-negative numbers
C. Float numbers
D. None of them
15. Values stored in a computer system's memory as a sequence of
A. Characters
B. Strings
C. Bits (0 and 1)
D. Float numbers
16. C++ requires every statement to end with a
A. Colon :
B. Question mark ?
C. Comma ,
D. Semi-colon ;
17. A variable is a symbol that represents
A. A number
B. A string
C. A storage location in the computer's memory
D. Nothing
18. The information that is stored in a variable is called as
A. String
B. Literal
C. Value
D. Operator
19. The sequence of instructions for a computer to execute, is called as
A. Program
B. Command
C. Query
D. Transaction
20. Int has a range of
A. 1 byte
B. 2 byte
C. 4 byte
D. 8 byte

4|Page
21. Unary operator means that
A. Operator takes only one operand
B. Operator takes two operand
C. Operator takes no value
D. None of them
22. Which symbol is used for horizontal tab in C++?
A. /t
B. \t
C. \a
D. \n
23. Empty string is denoted by
A. "0"
B. " "
C. 0;
D. 0
24. C++ is a
A. Case-sensitive language
B. Case-insensitive language
C. Only lowercase letter identifier
D. None of them
25. A variable in C++ cannot be used
A. Before it is declared
B. If it is of integer type
C. If it contains value less than 10
D. None of them
26. Post-increment operator is denoted by
A. + +m
B. m + +
C. m − −
D. − − m
27. The standard input and output library of C++ is
A. stdio.h
B. istream.h
C. iostream.h

5|Page
D. conio.h
28. The main ( ) function in the header of a program indicates what
A. It tells the compiler that where the program begins
B. It tells the compiler that it?s a C++ program
C. It tells the compiler that a comment is in the code
D. It indicates nothing
29. Why preprocessing directives are used? e.g. #include
A. It includes a header file.h into a source code
B. It includes declaration needed for input
C. It includes declaration needed for output
D. All of them
30. The main ( ) body of a program is enclosed in which kind of braces?
A. { }
B. [ ]
C. ( )
D. None of them
31. Which one of the following is a keyword?
A. Size
B. Key
C. (Jump
D. Switch
32. What is a constant that contains a single character enclosed within single quotes?
A. Character
B. Numeric
C. Fixed
D. Floating point
33. Logical AND (&&) and Logical OR (||) are ___ operators.
A. Logical
B. Equality
C. Class member
D. Comma
34. ______ operators have lower precedence to relational and arithmetic operators.
A. Conditional
B. Boolean

6|Page
C. Logical
D. Relational
35. ______ are data items whose value cannot be changed.
A. Class
B. Return
C. Constants
D. Variable
36. In C language, the break statement causes an exit
A. Only from the innermost switch
B. Only from the innermost loop
C. From all loops and switches
D. From the innermost loop or switch
37. In a for loop with a multi-statement, loop body semicolons should appear
A. The test expression
B. Each statement within the loop body
C. The closing brace in a multi-statement loop body
D. Both (a) and (b)
38. _____ are the kind of data that variables hold in a programming language.
A. Conditional type
B. Constant type
C. Variable type
D. Data types
39. The constant that should not have fractional part is ___
A. Float
B. Double
C. Integer
D. Exponent
40. What is the output of below program?

int main()
{
int a = 10;
cout<<a++;
return 0;

7|Page
}
A. 10
B. 11
C. 12
D. Not defined
41. What is the value of a in below program?

int main()
{
int a, b=20;
a = 90/b;
return 0;
}

A. 4.5
B. 4.0
C. 4
D. Compilation Error
42. How many times CppBuzz.com is printed?

int main()
{
int i=0;
lbl:
cout<<"CppBuzz.com";
i++;
if(i<5)
{
goto lbl;
}
return 0;

8|Page
A. Error
B. 5 times
C. 4 times
D. 6 times
43. Can we overload functions in C++?
A. Yes
B. No
C. Compilation Error
D. Runtime Error
44. What is correct syntax of for loop?
A. for(initialization;condition; increment/decrement)
B. for(increment/decrement; initialization; condition)
C. for(initialization, condition, increment/decrement
D. None of These
45. What should be the output of below program?

int main()
{
int a = 1;
switch(a)
{
case 1: cout<<"One";
case 2: cout<<"Two";
case 3: cout<<"Three";
default: cout<<"Default";
}
return 0;

A. One
B. Compilation Error
C. Default
D. OneTwoThree

9|Page
46. Can any function call itself?
A. Yes
B. No
C. Compilation Error
D. Runtime Error
47. What is output of below program?

int main()
{
int a=10;
int b,c;
b = a++;
c = a;
cout<<a<<b<<c;
return 0;
}

A. 111011
B. 111111
C. 101011
D. 101010
48. How many times 'it’s a while loop' should be printed?

int main()
{
int i = 1 ;
i=i-1;

while(i)
{
cout<<"its a while loop";
i++ ;
}

10 | P a g e
return 0;
}

A. 1
B. 2
C. 0
D. Infinite Times
49. What should be printed on screen?

int main()
{
int x = 5;

if(x++ == 5)
cout<<"Five"<<endl;
else
if(++x == 6)
cout<<"Six"<<endl;

return 0;
}

A. FiveSix
B. Five
C. Six
D. None of these
50. Find the output of below program?

int main()
{
int i = 0, x = 0;

do
{

11 | P a g e
if(i % 5 == 0)
{
cout<<x;
x++;
}

++i;
}while(i<10);

cout<<x;

return 0;
}

A. 01
B. 012
C. 0
D. 0123

Answers

1. D 11. B 21. A 31. D 41. C


2. A 12. C 22. B 32. A 42. B
3. E 13. B 23. B 33. A 43. A
4. D 14. B 24. A 34. D 44. A
5. B 15. C 25. A 35. C 45. D
6. D 16. D 26. B 36. D 46. A
7. D 17. C 27. C 37. D 47. A
8. A 18. C 28. A 38. D 48. C
9. C 19. A 29. D 39. C 49. B
10. B 20. C 30. A 40. A 50. B

12 | P a g e

You might also like