IMAGE CREDIT: TECHTRICKSWORLD |
QUESTION: 1
C++ was developed by……………..
(A) Thomas Kushz
(B) John Kemney
(C) Bjarne Stroutstrup
(D) James Goling
Ans: C
Bjarne Stroutstrup
QUESTION: 2
Which one of the following is a keyword?
(A) Size
(B) Key
(C) Jump
(D) Switch
Ans: D
Switch
QUESTION: 3
…………….Is the smallest individual unit in a program.
(A) Variable
(B) Contral
(C) Character
(D) Token
Ans: D
Token
QUESTION: 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
QUESTION: 5
The modulus operator uses………character.
(A) +
(B) *
(C) /
(D) %
ANS:%
QUESTION: 6
Every variable should be separate by ………..separator.
(A) Dot
(B) Colon
(C) Comma
(D) Semicolon
ANS:C
Comma
QUESTION: 7
Auto, Static, extern and register are called as……..
(A) Static
(B) Register
(C) Auto
(D) Storage specifier
ANS:D
Storage Specifier
QUESTION: 8
How many storage specifies are there in c++
(A) 2
(B) 3
(C) 4
(D) 5
ANS: C
4
QUESTION: 9
Signed, unsigned,long and short are some of the ………….
(A) Void
(B) Data
(C) Derived data
(D) Modifiers
ANS:D
Modifiers
QUESTION: 10
Logical And (&&) and logical OR(||) are ………..operators
(A) Logical
(B) Equality
(C) Class member
(D) Comma
ANS: A
LOGICAL
QUESTION 11
Which of
the following user-defined header file extension used in c++?
(A)Hg
(B) Cpp
(C) H
(D) Hf
ANS: C
H Explanation: .h extensions are used for user defined header files. To include a user defined header file one should use #include”name.h” i.e. enclosed within double quotes.
QUESTION 12
Which of
the following is a correct identifier in C++?
(A) VAR_1234
(B) $var_name
(C) 7VARNAME
(D) 7var_name
ANS: A
VAR_1234
QUESTION 13
What happens if the following C++ statement is compiled and executed?
INT*ptr =NULL
Delet ptr;
(A)The program is not semantically correct
(B) The program is compiled and executed
successfully
(C) The program gives a compile-time error
(D) The program compiled successfully but throws
an error during run-time.
ANS:B
The program is compiled and executed successfully
QUESTION 14
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}
(A) Hello
(B) World
(C) Error
(D) Hello World
ANS: C
Error
QUESTION 15
Which of the following type is
provided by C++ but not C?
(A) Double
(B) Float
(C) Int
(D) Bool
ANS: D
Bool
QUESTION 16
Which of the following correctly
declares an array in C++?
(A) array{10};
(B) array array10];
(C) int array;
(D) int array [10];
ANS: D
int array [10];
QUESTION 17
Which of the following is used to
terminate the function declaration in C++?
(A)=;
(B=]
(C)=)
(D)=(
ANS:A
;
QUESTION 18
What is meant by a polymorphism
in C++?
(A) class having only single form
(B) class having four forms
(C) class having many forms
(D) class having two forms
ANS: C
Class having four forms
QUESTION 19
Pick the incorrect statement
about inline functions in C++?
(A) Saves overhead of a return call from a function
(B) They are generally very large and complicated
function
(C) These functions are inserted/substituted at
the point of call
(D) They reduce function call overheads
ANS:B
They are generally very large and complicated function
QUESTION 20
Which concept allows you to reuse
the written code in C++?
(A) Inheritance
(B) Polymorphism
(C) Abstraction
(D) Encapsulation
ANS: A
Inheritance
QUESTION 21
What will be the output of the following C++ program?
#include<iostream>
#include<string>
Using namespace std;
Int main()
String str{sanfoundry};
(A) Runtime error
(B) Sanfo
(C) S
(D) Sanfoundry
ANS:A
Runtime error
QUESTION 22
What will be the output of the following C++ code snippet?
#include <stdio.h>
#include<iostream>
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) 21
b) 27
c) 26
d) 25
Ans: D
Explanation: We are adding all the elements in the array and printing it. Total
elements in the array is 7, but our for loop will go beyond 7 and add a garbage
value.
QUESTION 23
What will be the output of the following C++ program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("Sanfoundry");
for (size_t i = 0; i < str.length();)
{
cout << str.at(i-1);
}
return 0;
}
(A) runtime error
(B) Sanfo
(C) S
(D ) Sanfoundry
Ans: A
Explanation: This program will terminate because the cout element is out of
range.
QUESTION 24
What will be the output of the following C++ program?
#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<"Constructor called\n";
}
~A(){
cout<<"Destructor called\n";
}
};
int main(int argc, char const *argv[])
{
A *a = new A[5];
delete[] a;
return 0;
}
(A) Segmentation fault
(B) “Constructor called” five times and then “Destructor called” five times
(C) “Constructor called” five times and then “Destructor called” once
(D)Error
Ans: B
“Constructor called” five times and then
“Destructor called” five
QUESTION 25
What does the function objects implement?
(A)Operator
(B) Operator()
(C) Operand
(D) Operand<>
ANS:D
Operand<>
QUESTION 26
What
are the two advantage of function objects than the function call?
(A)It contains a state
(B) It is a type
(C) It contains a state & It is a type
(D) It contains a prototype
ANS: C
It contains a state & It is a type
ANS:A
It contains a state
QUESTION 27
Which are
instances of a class with member function operator() when it is defined?
(A) function objects
(B) member
(C) methods
(D) iterators
ANS: A
Function objects
QUESTION 28
How many parameters does a operator() in a
function object shoud take?
(a) 1
(b) 2
(c) 3
(d) 4
ANS:D
4
Post a Comment