C++++++++ Docx Bak-1
C++++++++ Docx Bak-1
a) Dennis Ritchie
b) Ken Thompson
c) Brian Kernighan
d) Bjarne Stroustrup
Answer: d
2. What is C++?
Answer: c
3. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include [userdefined]
b) #include “userdefined”
c) #include <userdefined.h>
d) #include <userdefined>
Answer: b
a) /* comment */
b) // comment */
c) // comment
Answer: d.
a) hg
b) cpp
c) h
d) hf
Answer: c
a) VAR_1234
b) $var_name
c) 7VARNAME
d) 7var_name
Answer: a
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) Friend constructor
Answer: d
a) Left-right
b) Right-left
c) Bottom-up
d) Top-down
b) C++ technique to ensure that a private member of the base class can be accessed somehow
d) C++ technique to avoid multiple copies of the base class into children/derived class
Answer: d
10. What happens if the following C++ statement is compiled and executed?
delete ptr;
a) The program is not semantically correct
Answer: b
#include <iostream>
#include <string>
cout<<s3;
return 0;
a) Hello
b) World
c) Error
d) Hello World
Answer: c
a) delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case
b) delete is used to delete normal objects whereas delete[] is used to pointer objects
d) delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects
Answer: d
int main(void)
int new = 5;
printf("%d", new);
Answer: c
#include <stdio.h>
void func(void)
printf("Hello");
void main()
func();
func(2);
Answer: d
Answer: c
#include <iostream>
#include <string>
#include <algorithm>
int main()
a) spacesintext
b) spaces in text
c) spaces
d) spaces in
Answer: a
17. Which of the following C++ code will give error on compilation?
================code 1=================
#include <iostream>
cout<<"Hello World";
return 0;
}
========================================
================code 2=================
#include <iostream>
std::cout<<"Hello World";
return 0;
========================================
a) Code 1 only
d) Code 2 only
Answer: b
a) double
b) float
c) int
d) bool
Answer: d
#include <iostream>
int main()
int p;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p = ((x | y) + (a + b));
cout << p;
return 0;
a) 12
b) 0
c) 2
d) 16
Answer: d
20. By default, all the files in C++ are opened in _________ mode.
a) Binary
b) VTC
c) Text
d) ISCII
Answer: c
int main()
register int i = 1;
return 0;
c) 1
d) 0
Answer: b.
22. Which of the following correctly declares an array in C++?
a) array{10};
b) array array[10];
c) int array;
d) int array[10];
Answer: d
b) 2 or 4
c) 4
d) 2
Answer: a.
#include<iostream>
int main ()
int cin;
return 0;
a) Segmentation fault
b) Nothing is printed
c) Error
Answer: d
Answer: c
a) call by object
b) call by pointer
c) call by value
d) call by reference
Answer: d
#include <iostream>
#include <string>
#include <cstring>
cout<<a;
return 0;
a) Hello
b) World
c) Error
d) Hello World
Answer: a
28. Which of the following is used to terminate the function declaration in C++?
a) ;
b) ]
c) )
d) :
Answer: a
#include <iostream>
int main()
char c = 74;
cout << c;
return 0;
a) I
b) J
c) A
d) N
Answer: b
#include <iomanip>
#include <iostream>
int main()
double d = 0.1;
return 0;
c) 0.11
d) 0.10000000000000001
Answer: d
a) #macro
b) #define
c) macro
d) define
Answer: b
32. What is the correct syntax of accessing a static member of a class in C++?
---------------------------
Example class:
class A
public:
---------------------------
a) A->value
b) A^value
c) A.value
d) A::value
Answer: d
33. The C++ code which causes abnormal termination/behaviour of a program should be written under
_________ block.
a) catch
b) throw
c) try
d) finally
Answer: c.
b) Overloading of classes
Answer: a
#include <iostream>
int main()
int a = 5;
float b;
cout << a;
return 0;
a) 2 5
b) 4 5
c) 4 6
d) 2 6
Answer: b
36. Which of the following symbol is used to declare the preprocessor directives in C++?
a) $
b) ^
c) #
d) *
Answer: c.
#include<iostream>
int main()
int a = 5;
a = 10;
};
check();
cout<<"Value of a: "<<a<<endl;
return 0;
a) Segmentation fault
b) Value of a: 5
c) Value of a: 10
d) Error
Answer: d
#include <iostream>
*x = (*x) * --(*y);
int main ( )
{
int number = 30;
square(&number, &number);
return 0;
a) 30
b) Error
c) Segmentation fault
d) 870
Answer: d
Answer: c
#include <iostream>
#include <string>
int main ()
str.back() = '!';
return 0;
a) Sanfoundry!
b) Sanfoundry!.
c) Sanfoundry.
d) Sanfoundry.!
Answer: a
Answer: b
#include <iostream>
int main()
int n = 5;
void *p = &n;
return 0;
a) 5
b) 6
d) runtime error
Answer: a
c) Class specifically used as a base class with atleast one virtual functions
d) Class specifically used as a base class with atleast one pure virtual functions
Answer: d
44. Which of the following constructors are provided by the C++ compiler if not defined in a class?
a) Copy constructor
b) Default constructor
c) Assignment constructor
Answer: d
#include <iostream>
int main()
try
try
throw 20;
catch (int n)
throw;
catch (int x)
}
return 0;
a) Outer Catch
b)
Inner Catch
Outer Catch
c) Error
d) Inner Catch
Answer: b
46. Which concept allows you to reuse the written code in C++?
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation
Answer: a
47. What will be the output of the following C++ code snippet?
#include <iostream>
return (a * b);
return (a / b);
int main()
{
int x = 5, y = 2;
return 0;
a) 10.0 5
b) 10 2.5
c) 10.0 5.0
d) 5.0 2.5
Answer: b
b) In Structures, members are public by default whereas, in Classes, they are private by default
d) In Structures, members are private by default whereas, in Classes, they are public by default
Answer: b
#include <iostream>
int main ()
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}
a) 12
b) 14
c) 6
d) 7
Answer: d
50. What is the benefit of c++ input and output over c input and output?
b) Sequence container
c) Exception
d) Type safety
Answer: d
51. What will be the output of the following C++ code snippet?
#include <stdio.h>
#include<iostream>
int main ()
int n, result = 0;
result += array[n];
return 0;
a) 21
b) 27
c) 26
d) 25
Answer: b
#include <iostream>
#include <string>
int main ()
return 0;
a) runtime error
b) Sanfo
c) S
d) Sanfoundry
Answer: a
#include <iostream>
class A{
public:
A(){
cout<<"Constructor called\n";
~A(){
cout<<"Destructor called\n";
};
A *a = new A[5];
delete[] a;
return 0;
a) Segmentation fault
b) “Constructor called” five times and then “Destructor called” five times
d) Error
Answer: b