MCQ C++edition+
MCQ C++edition+
(A) Size
(B) Key
(C) Jump
(D) Switch
Ans: D :Switch
(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
Ans: A ::Character
(A) +
(B) *
(C) /
(D) %
Ans: D :::%
(B) Print f( )
(C) SCAN( )
(D) Main( )
(B) Constant
(C) Pointer
(D) Integer
9- Enumeration is a
(A) Statements
(B) Functions
(C) Arrays
(D) Pointer
C.Operator-&&
D.Operator +
15- ____ operators have lower precedence to relational and arithmetic operators.
(A) Conditional
(B) Boolean
(C) Logical
(D) Relational
Ans: D :: Relational
A. double
B. float
C. char
D. floating
Ans : B
A. 0 byte
B. 1byte
C. 2byte
D. 3byte
Ans : B
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
A. float
B. double
C. long double
D. unsigned long long int
Ans : C
29- Which of the following function / types of function cannot have default
parameters?
Ans : B
Explanation: None
Ans : A
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
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
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
Answer:b
Answer:c
Answer:d
Answer:a
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
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];
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();
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
28. What is required to avoid falling through from one case to the next?
A. end;
B. break;
C. Stop;
D. A semicolon.
switch(x)
case 1: cout<<"One";
case 0: cout<<"Zero";
}
A. One
B. Zero
C. Hello World
D. ZeroHello World
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);
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 )
42. Which of the following is the correct operator to compare two variables?
A. :=
B. =
C. equal
D. ==
#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
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
Ans : A
#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
Ans : B
Explanation: a[1][2] means 1 * (4)+2 = 6th element of an array starting from
zero