0% found this document useful (0 votes)
121 views27 pages

MCQ C++edition+

This document contains 30 multiple choice questions about C++ concepts like arrays, loops, functions, data types, and more. Each question is followed by 4 possible answers with one correct answer indicated. The questions cover a range of fundamental C++ topics to test understanding of basic syntax, logic, and programming concepts.

Uploaded by

aam5112002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views27 pages

MCQ C++edition+

This document contains 30 multiple choice questions about C++ concepts like arrays, loops, functions, data types, and more. Each question is followed by 4 possible answers with one correct answer indicated. The questions cover a range of fundamental C++ topics to test understanding of basic syntax, logic, and programming concepts.

Uploaded by

aam5112002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Questions and answers MCQ

1- C++ was developed by ___

(A) Thomas Kushz

(B) John Kemney

(C) Bjarne Stroutstrup

(D) James Goling

Ans: C ::Bjarne Stroutstrup

2- Which one of the following is a keyword?

(A) Size

(B) Key

(C) Jump

(D) Switch

Ans: D :Switch

3- ____ is the smallest individual unit in a program.

(A) Variable

(B) Control

(C) Character

(D) Token

Ans: D :: Token

4- What is a constant that contains a single character enclosed within single quotes?

(A) Character

(B) Numeric
(C) Fixed

(D) Floating point

Ans: A ::Character

5- The modulus operator uses ___ character.

(A) +

(B) *

(C) /

(D) %

Ans: D :::%

6- Almost every C program begins with the statement

(A) # include <stdio.h>

(B) Print f( )

(C) SCAN( )

(D) Main( )

Ans: A:: # include <stdio.h>

7- The two operators && and || are

(A) Relational operators

(B) Equality operators

(C) Arithmetic operators

(D) Logical operators

Ans: D:: Logical operators

8- A variable that holds the memory address of another object is called


(A) Memory variable

(B) Constant

(C) Pointer

(D) Integer

Ans: C:: Pointer

9- Enumeration is a

(A) Set of legal values possible for a variable

(B) List of operators

(C) List of strings

(D) Set of numbers

Ans: A:: Set of legal values possible for a variable

10- In C, square brackets [ ] are used in

(A) Statements

(B) Functions

(C) Arrays

(D) Pointer

Ans: C:: Arrays

11- Which one is not a correct variable type in C++?


A.float
B.real
C.int
D.double

Answer : real [Option : B]


12- Which operation is used as Logical 'AND'
A.Operator-&
B.Operator-||

C.Operator-&&
D.Operator +

Answer : Operator-&& [Option : C

13- An expression A.B in C++ means ____


A.A is member of object B
B.B is member of Object A
C.Product of A and B
D.None of these

Answer : B is member of Object A [Option : B]

14- A C++ code line ends with ___


A.A Semicolon (;)
B.A Fullstop(.)
C.A Comma (,)
D.A Slash (/)

Answer : A Semicolon (;) [Option : A]

15- ____ operators have lower precedence to relational and arithmetic operators.
(A) Conditional
(B) Boolean
(C) Logical
(D) Relational
Ans: D :: Relational

16-How many C++ data types are broadly classified?


(A) 2
(B) 3
(C) 4
(D) 5
Ans: B ::3
17-Float and double are related to ____ data type.
(A) Void
(B) Floating
(C) Fixed
(D) Integral
Ans: B ::Floating

18-Variable names must begin with ___


(A) #
(B) $
(C) Number
(D) Letter
Ans: D :: Letter

19-Integer values are stored in ___ bit format in binary form.


(A) 8
(B) 16
(C) 32
(D) 64
Ans: B ::16

20-Every variable should be separated by ___ separator.


(A) Dot
(B) Colon
(C) Comma
(D) Semicolon
Ans: C ::Comma

21-Auto, static, extern and register are called as ___


(A) Static
(B) Register
(C) Auto
(D) Storage specifier
Ans: D ::Storage specifier
22- How many storage specifies are there in a C++?
(A) 2
(B) 3
(C) 4
(D) 5
Ans: C :: 4

23-Signed, unsigned, long and short are some of the ___


(A) Void
(B) Data
(C) Derived data
(D) Modifiers
Ans: D ::Modifiers

24-Logical AND (&&) and Logical OR (||) are ___ operators.


(A) Logical
(B) Equality
(C) Class member
(D) Comma
Ans: A ::Logical

25-. Keyword of Floating point is?

A. double
B. float
C. char
D. floating

Ans : B

Explanation: Keyword of Floating point is float

26- Typical bit width of char is?

A. 0 byte
B. 1byte
C. 2byte
D. 3byte

Ans : B

Explanation: Typical bit width of char is 1 byte

27- Typical range of unsigned int?

A. -127 to 127
B. 0 to 65,535
C. 0 to 4294967295
D. -2,147,483,648 to 2,147,483,647

Ans : C

Explanation: Typical range of unsigned int is 0 to 4294967295

28- Which type has typical bit width 12 bytes?

A. float
B. double
C. long double
D. unsigned long long int

Ans : C

Explanation: long double has typical bit width 12 bytes

29- Which of the following function / types of function cannot have default
parameters?

A. Member function of class


B. Main()
C. Member function of structure
D. Both B and C

Ans : B

Explanation: None

30- Correct way to declare pure virtual function in a C++ class is

A. Virtual void foo() =0 ;


B. Void virtual foo()= { 0 }
C. Virtual void foo() {} = 0;
D. None of the above

Ans : A

Explanation: A is the correct declaration of pure virtual function in a class in


C++.NOTE: Pure virtual function is used in an Interface or an abstract class

31- What is the scope of the variable declared in the user defined function?

A. Whole program
B. Only inside the {} block
C. The main function
D. None of the above

Ans : B

Explanation: The variable is valid only in the function block as in other.


C++ Array and matrices Solved MCQs Questions Answers

1. Which of the following correctly declares an array?


a) int array[10];
b) int array;
c) array{10};
d) array array[10];

Answer:a

2. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined

Answer:b

3. 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

Answer:a

4. Which of the following accesses the seventh element stored in array?


a) array[6];
b) array[7];
c) array(7);
d) array;

Answer:a

5. 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;

Answer:d

6. 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

Answer:b

7. 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

Answer:c

8. 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

Answer:d

9. 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

Answer:a

10. 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

Answer:b
11-Which of the following correctly declares an array?
A. int anarray[10];
B. int anarray;
C. anarray{10};
D. array anarray[10];

12. What is the index number of the last element of an array with 29
elements?
A. 29
B. 28
C. 0
D. Programmer-defined

13. Which of the following is a two-dimensional array?


A. array anarray[20][20];
B. int anarray[20][20];
C. int array[20, 20];
D. char array[20];

14. Which of the following correctly accesses the seventh element stored
in foo, an array with 100 elements?
A. foo[6];
B. foo[7];
C. foo(7);
D. foo;

15. Which of the following gives the memory address of the first element
in array foo, an array with 100 elements?
A. foo[0];
B. foo;
C. &foo;
D. foo[1];

If you didn't do as well as you would have liked, be sure to read


through Cprogramming.com's tutorial on if statments in C and C++.
Otherwise, congratulations!

16. Which of the following is true?


A. 1
B. 66
C. .1
D. -1
E. All of the above

17. Which of the following is the boolean operator for logical-and?


A. &
B. &&
C. |
D. |&

18. Evaluate !(1 && !(0 || 1)).


A. True
B. False
C. Unevaluatable
19. Which of the following shows the correct syntax for an if statement?
A. if expression
B. if { expression
C. if ( expression )
D. expression if
If you didn't do as well as you would have liked, be sure to read
through Cprogramming.com's tutorial on lesson4.html. Otherwise, well done!

20. Which is not a proper prototype?


A. int funct(char x, char y);
B. double funct(char x)
C. void funct();
D. char x();

21. What is the return type of the function with prototype: "int func(char x,
float v, double t);"
A. char
B. int
C. float
D. double

22. Which of the following is a valid function call (assuming the function
exists)?
A. funct;
B. funct x, y;
C. funct();
D. int funct();

23. Which of the following is a complete function?


A. int funct();
B. int funct(int x) {return x=x+1;}
C. void funct(int) {cout&tl;<"Hello"}
D. void funct(x) {cout<<"Hello"}

24. What is the final value of x when the code int x; for(x=0; x<10;
x++) {} is run?
A. 10
B. 9
C. 0
D. 1

Note: This quiz question probably generates more email to the


webmaster than any other single item on the site. Yes, the answer
really is 10. If you don't understand why, think about it this way: what
condition has to be true for the loop to stop running?

25. When does the code block following while(x<100) execute?


A. When x is less than one hundred
B. When x is greater than one hundred
C. When x is equal to one hundred
D. While it wishes
26. Which is not a loop structure?
A. For
B. Do while
C. While
D. Repeat Until

4. How many times is a do while loop guaranteed to loop?


A. 0
B. Infinitely
C. 1
D. Variable

If you didn't do as well as you like, be sure to read


through Cprogramming.com's tutorial on Switch..Case. Otherwise,
congratulations!

27. Which follows the case statement?


A. :
B. ;
C. -
D. A newline

28. What is required to avoid falling through from one case to the next?
A. end;
B. break;
C. Stop;
D. A semicolon.

29. What keyword covers unhandled possibilities?


A. all
B. contingency
C. default
D. other

30. What is the result of the following code?


int x=0;

switch(x)

case 1: cout<<"One";

case 0: cout<<"Zero";

case 2: cout<<"Hello World";

}
A. One
B. Zero
C. Hello World
D. ZeroHello World

If you didn't do as well as you wanted to, be sure to read


through Cprogramming.com's tutorial on C-style Strings. Otherwise,
congratulations, you're almost halfway through the tutorials!

31. Which of the following is a static string?


A. Static String
B. "Static String"
C. 'Static String'
D. char string[100];

32. What character ends all strings?


A. '.'
B. ' '
C. '\0'
D. '\n'

33. Which of the following reads in a string named x with one hundred
characters?
A. cin.getline(x, 100, '\n');
B. cin.getline(100, x, '\n');
C. readline(x, 100, '\n');
D. read(x);

34. Which of the following functions compares two strings?


A. compare();
B. stringcompare();
C. cmp();
D. strcmp();

35. Which of the following adds one string to the end of another?
A. append();
B. stringadd();
C. strcat();
D. stradd();

36. What is the correct value to return to the operating system upon the
successful completion of a program?
A. -1
B. 1
C. 0
D. Programs do not return a value.

37. What is the only function all C++ programs must contain?
A. start()
B. system()
C. main()
D. program()

38. What punctuation is used to signal the beginning and end of code blocks?
A. { }
B. -> and
C. BEGIN and END
D. ( and )

39. What punctuation ends most lines of C++ code?


A. .
B. ;
C. :
D. '

40. Which of the following is a correct comment?


A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }

41. Which of the following is not a correct variable type?


A. float
B. real
C. int
D. double

42. Which of the following is the correct operator to compare two variables?
A. :=
B. =
C. equal
D. ==

43. The array can be described as?


A. Data structure
B. A container having similar values
C. Not a data structure
D. None of these
Answer: B
44. Syntax to initialize an array in C is?
A. int arr[3]={1,2,3};
B. int arr(3)=(1,2,3);
C. int arr{3}=[1,2,3];
D. All of these
Answer: A
45.Advantage of an array is?
A. Stores Element
B. index of the element is 1
C. Stores many elements with the same data type
D. None of these
Answer: C
46. Index of an array starts with?
A. 1
B. 2
C. 3
D. 0
Answer: D
47. Arrays elements can be accessed?
A. Exponentially
B. Logarithmically
C. Randomly
D. Both B and C
Answer: C
48. Dimensions of an array in C are?
A. 2
B. 3
C. 4
D. No limit
Answer: D
49. Data types of the array include?
A. int
B. float
C. char, double, struct
D. All of these
Answer: D
50. The function called to passed the entire array?
A. Call by reference
B. Call by value
C. Both A and B
D. None of these
Answer: A
51. To read the multi-word string we use the function?
A. puts()
B. gets()
C. scanf()
D. All of these
Answer: B
52. What do we use to access the seven-element of an array?
A. arr[6]
B. arr[7]
C. Both A and B
D. arr{7}
Answer: A
53. int a[5]={1,3,2}. What will be the value of a[4]?
A. 3
B. 2
C. 0
D. Garbage value
Answer: A
54. The sequence of objects having the same data type, is called?
A. Stacks
B. Functions
C. Arrays
D. None of these
Answer: C
55. The object of an array is?
A. Functions of array
B. Elements of array
C. Indexes of array
D. None of these
Answer: B
56. In a binary search, we use an algorithm called?
A. Bubble sort
B. Liner way
C. Both A and B
D. Divide and conquer
Answer: D
57. Size of an Array does not required, when?
A. It is a declaration
B. Initialization is part of the definition
C. Both A and B
D. It is a formal parameter
Answer: B
58. Operator use to allocates memory to array variable in java?
A. New
B. New malloc
C. Alloc
D. Malloc
Answer: A
59. What is the index of the last element having 9 elements?
A. 7
B. 9
C. 8
D. 0
Answer: C
60. Arr[6] access which element stored in an array?
A. 6
B. 7
C. 0
D. 5
Answer: D
61. What is the length of array {1,3,4,2,4}
A. 5
B. 4
C. 3
D. None of these
Answer: B
62. Referring element outside from array bound?
A. Logical error
B. Execution time error
C. Both B and C
D. Syntax error
Answer: C
63. One dimension array of one-dimensional arrays is called?
A. Two dimensional array
B. One dimensional array
C. Multi casting array
D. None of these
Answer:A
Pointers Solved MCQs Questions Answers
Let us see the Pointers Solved MCQs Questions Answers.
1. we can manipulate data stored in other variables ________ with pointer
variables.
a. All of these
b. never
c. seldom
d. indirectly
e. none of these
f. both a and b
Answer d
2.following statement has the same meaning as
int *ptr;
a. int* ptr;
b. int ptr;
c. *int ptr;
d. int ptr*;
e. none of these
f. both a and b
Answer a
3.which of the following options can be used as pointers.
a. All of these
b. Array names
c. Numeric constants
d. Punctuation marks
e. None of these
e. none of these
f. both c and b
Answer b
4. which of the following operators are used to increment or decrement a
pointer variable.
a. modulus, division
b. addition, subtraction
c. ++, —
d. +-,-+
e. None of these
e. none of these
d. both c and d
Answer c
5. ________ is used to initialize a pointer.
a. all of these
b. the address of an existing object
c. the value of an integer variable
d. the value of a floating-point variable
e. none of these
f. both a and b
Answer b
6. What is the function of the following statement?
double *num2;
a. Declares a pointer variable named num2.
b. Declares a double variable named num2.
c. Declares and initializes a pointer variable named num2.
d. Initializes a variable named *num2.
e. none of these
f. both a and b
Answer a
7. the delete operator can be used on the pointers:
a. dereferenced inappropriately
b. never used
c. not correctly initialized
d. created with the new operator
e. none of these
f. both a and b
Answer d
8. Which of the following are invalid statements?
a. float num1 = &ptr2;
b. int ptr = &num1;
c. int ptr = int *num1;
d. All of these are invalid
e. All of these are valid
f. both a and b
Answer d
9.what is stored in a pointer variable?
a. an integer
b. a memory address.
c. only floating-point values.
d. any C++ value.
e. none of these
d. both a and b
Answer b
10.pointer variables may be changed with mathematical statements that
perform___________.
a. special operations
b. all mathematical operations
c.multiplication and division
d. addition and subtraction
e. none of these
f. both a and b
Answer d
11. Reference is not the same as a pointer because
A. a reference can never be null
B. a reference once established cannot be changed.
C. reference doesn’t need an explicit dereferencing mechanism.
D. All of above
e. none of these
d. both a and b
Answer c
12. size of generic pointer is _______.
A. 0
B. 1
C. 2
D. 3
e. none of these
d. both a and b
Answer c
13. Referencing a value through a pointer is called
a. All of them
b. Direct calling
c. Indirection
d. Pointer referencing
e. none of these
d. both a and b
Answer c
14.Generic pointers can be declared with__________ .
A. void
B. asm
C. auto
D. all of the above
e. none of these
d. both a and c
Answer a
15. Which of the following is true about the following program

#include <iostream>
using namespace std;
int main()
{
int i;
char *lfc[] = {"C", "C++", "Java", "VBA"};
char *(*ptr)[4] = &lfc;
cout << ++(*ptr)[2];
return 0;
}
A. ava
B. java
C. c++
D. compile time error
Ans : A

Explanation: In this program we are moving the pointer from first position to
second position and printing the remaining value.
16. What will be the output of this program?
Note:Includes all required header files
using namespace std;
int main()
{
int find[] = {1, 2, 3, 4};
int *p = (find + 1);
cout << *p;
return 0;
}
A. 1
B. 2
C. 3
D. 4
Ans : B

Explanation: In this program, we are making the pointer point to next value
and printing it.
17. What will be the output of this program?
Note:Includes all required header files
using namespace std;
int main()
{
int find[] = {1, 2, 3, 4};
int *p = (find + 1);
cout << find;
return 0;
}
A. 1
B. 2
C. address of find
D. 4
Ans : C

Explanation: As we counted to print only find, it will print the address of the
array.
18. What will be the output of the following program?
Note:Includes all required header files
using namespace std;
int main()
{
int find[] = {1, 2, 3, 4};
int *p = (find + 1);
cout << *find + 9;
return 0;
}
A. 9
B. 10
C. 11
D. error
Ans : B

Explanation: In this program, we are adding the value 9 to the initial value of
the array, So it's printing as 13.
19. What will be the output of the following program?
Note:Includes all required header files
using namespace std;
int main ()
{
int find[5];
int * p;
p = find; *p = 1;
p++; *p = 2;
p = &find[2]; *p = 3;
p = find + 3; *p = 4;
p = find; *(p + 4) = 5;
for (int n = 0; n < 5; n++)
cout << find[n] << ",";
return 0;
}
A. 1,2,3,4,5,
B. 12345
C. compile error
D. runtime error
Ans : A

Explanation: In this program, we are just assigning a value to the array and
printing it and immediately dereferencing it.
20. The correct statement for a function that takes pointer to a float, a pointer
to a pointer to a char and returns a pointer to a pointer to a integer is

A. int **fun(float**, char**)


B. int *fun(float*, char*)
C. int ***fun(float*, char**)
D. int ***fun(*float, **char)

Ans : C

Explanation: The correct statement for a function that takes pointer to a float,
a pointer to a pointer to a char and returns a pointer to a pointer to a integer is
int ***fun(float*, char**).
21-What is the output of this program?

#include <iostream>
using namespace std;
int main()
{
int x = 1, y = 3, z = 5;
int *lfc[ ] = {&x, &y, &z};
cout << lfc[1];
return 0;
}
A. 1
B. 3
C. 5
D. it will return some random number

Ans : D

Explanation: array element cannot be address of auto variable. It can be


address of static or extern variables.
22- What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
char lfc[20];
int i;
for(i = 0; i < 10; i++)
*(lfc + i) = 65 + i;
*(lfc + i) = ' ';
cout << lfc;
return(0);
}
A. ABCDEFGHIJ
B. AAAAAAAAAA
C. JJJJJJJJ
D. None of the mentioned

Ans : A

Explanation: Each time we are assigning 65 + i. In first iteration i = 0 and 65 is


assigned. So it will print from A to J.

23- What is the output of this program?

#include <iostream>
using namespace std;
int main()
{
char *ptr;
char Str[] = "abcdefg";
ptr = Str;
ptr += 5;
cout << ptr;
return 0;

}
A. fg
B. cdef
C. defg
D. abcd

Ans : A

Explanation: Pointer ptr points to string "fg". So it prints fg.


24- Which of the following statement is correct about the program given
below?
Note:Includes all required header files
using namespace std;
int main()
{
int a[2][4] = {1, 2, 3, 4, 5, 6, 7, 8};
cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
return 0;
}
A. 5 6 7
B. 7 7 7
C. 8 8 8
D. Compile time error

Ans : B
Explanation: a[1][2] means 1 * (4)+2 = 6th element of an array starting from
zero

You might also like