



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















A.Float B.real C.int D. double
A.Operator-& B.Operator-|| C.Operator-&& D. Operator +
A.A Semicolon (;) B.A Fullstop(.) C.A Comma (,) D.A Slash (/)
A.Nuclear Family Class B.Abstruct Class C.SigletonClass D.Numero Uno Class
A.Polymorphism B.Inheritance C.Encapsulation D.Both A and B
A.Public B.Private C.Protected D.Static
A.Run
Time
B.Compile Time C.Debug Time D.Coding Time
A.
a) Dennis Ritchie
b) Ken Thompson
c)Brian Kernighan
d) Bjarne Stroustrup
Answer: d
Explanation: Bjarne Stroustrup is the original creator of C++ in 1979 at
AT&T Bell Labs
C++ is an object oriented programming
language
a)
b) C++ is a procedural programming
language
c) C++ supports both procedural and object oriented programming
language d) C++ is a functional programming
language
Answer: c
Explanation: C++ supports both procedural(step by step instruction)
and object oriented programming (using the concept of classes and
objects).
a) /* comment */
b) // comment */
c)// comment
d) both // comment or /* comment */
Answer: d
Explanation: Both the ways are used for commenting in C++
programming. // is used for single line comments and /* … */ is used
for multiple line comments.
a) hg
b) cpp
c)h
d) hf
Answer: c
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.
#include
#include
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 ;
}
================code 1 =================
#include
using namespace std;
int main(int argc,
char const *argv[])
{
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
Answer: b
Explanation: The above statement is syntactically and semantically
correct as C++ allows the programmer to delete a NULL pointer,
therefore, the program is
compiled and executed successfully.
a) Hello
b) World
c)Error
d) Hello World
Answer: c
Explanation: There is no operation defined for the addition of character
array in C++ hence the compiler throws an error as it does not
understood what to do about this expression.
a)Code 1 only
b) Neither code 1 nor code 2
c) Both code 1 and code 2
d) Code 2 only
Answer: b
Explanation: Neither code 1 nor code 2 will give an error as both are
syntactically correct as in first code we have included namespace std and
in second one we have used scope resolution operator to resolve the
conflict.
e) Binary
f) VTC
g)Text
h) ISCII
Answer: c
Explanation: By default, all the files in C++ are opened in text mode. They
read the file as normal text.
i) array{10};
j) array array[10];
k)int array;
l) int array[10];
cout<<"Hello World";
return 0 ;
}
========================================
================code 2 =================
#include
int main(int argc, char const *argv[])
{
std::cout<<"Hello World";
return 0 ;
}
=========================
===============
#include
using namespace std;
int main()
{
c))
d) :
Answer: a
Explanation: ; semicolon is used to terminate a function declaration
statement in C++.
Example class:
class A
{
public:
static int value;
}
e) A->value
f) A^value
g)A.value
h) A::value
Answer: d
Explanation: Scope resolution operator(::) is used to access a static
member of a class.
i) Deriving new classes from existing classes
j) Overloading of classes
k)Classes with same names
l) Wrapping of data into a single class
Answer: a
Explanation: Inheritance is the concept of OOPs in which new classes are
derived from existing classes in order to reuse the properties of classes
defined earlier.
$ g++ size3.cpp
$ a.out
4 5
#include
using namespace std;
void square (int *x, int *y)
{
x = (x) * --(*y);
}
int main ( )
{
int number = 30 ;
square(&number, &number);
cout << number;
return 0 ;
}
a) 2 5
b) 4 5
c) 4 6
d) 2 6
Answer: b
Explanation: The a as a integer will be converted to float while calculating
the size. The value of any variable doesn’t modify inside sizeof operator.
Hence value of variable a will remain 5.
Output:
a) 30
b) Error
c)Segmentation
fault d) 870
Answer: d
Explanation: As we
are passing value
by reference
therefore the
change in the
value is
int a = 5 ;
float b;
cout << sizeof(++a + b);
cout << a;
return 0 ;
}
3.int operate (int a, int b) 4.
{
b); 6. }
2.0;
y) <<" \t ";
m);
c)Assignment constructor
d) All of the mentioned
Answer: d
Explanation: If a programmer does not define the above constructors in a
class the C++ compiler by default provides these constructors to avoid error
on basic operations.
e) Inheritance
f) Polymorphism
g)Abstraction
h) Encapsulation
Answer: a
Explanation: Inheritance allows you to reuse your already written code by
inheriting the properties of written code into other parts of the code, hence
allowing you to reuse the already written code.
a) 10.0 5
b) 10
2.5 c)
d) 5.0 2.
20.$ a.out 21.
10 2.
Answer: b
Explanation: In this program, we are divide and multiply the
values. Output:
a) Structures by default hide every member whereas classes do not
b)In Structures, members are public by default whereas, in Classes, they are
private by default
c)Structures cannot have private members whereas classes can have
d)In Structures, members are private by default whereas, in Classes, they are
public by default
Answer: b
Explanation: Structure members are public by default whereas, class
members are private by default. Both of them can have private and
public members.
a)
b) 27
c) 26
d) 25
$ g++ op3.cpp
$ a.out
5 6
#include
using namespace std;
int main()
{
int i, j;
j = 10 ;
i = (j++,
j + 100 ,
999 + j);
cout << i;
return 0 ;
Answer: b
Explanation: Because the * operator is having highest precedence, So it is
executed first and then the + operator will be executed
a) 5 6
b) 6 5
c) 6 7
d) 6 8
Answer: a
Explanation: It is a separator here. In C, the value a is stored in c and in d the
value b is stored in d because of the bracket.
Output:
$ g++ op.cpp
$ a.out
749735
a)
b) 11
c)
d)
Answer
: c
Explan
ation: j
starts
with
the
value
then
increm
ented
to 11.
Next, j
is
added
to
result 1010. Output:
a)
b)
c)
d)
Answer:
a
Explanation: Because of the precedence the pre-increment and post
increment operator, we got the output as 749736.
Output:
$ g++ op2.cpp
$ a.out
1010
d) Polymorphism
Answer: c
Explanation: Inheritance allows you to reuse your already written code by
inheriting the properties of written code into other parts of the code, hence
allowing you to reuse the already written code.
a) They does not helps in any way
b) They allows us to show only required things to outer world
c)They help in keeping things together
d) Abstraction concept is not used in classes
Answer: b
Explanation: Abstraction is the concept of hiding things from the outer world
and showing only the required things to the world, which is where access
specifiers private, protected and public helps in keeping our knowledge
hidden from the world.
a) procedural programming language
b) object oriented programming language
c)functional programming language
d) both procedural and object oriented programming language
Answer: d
Explanation: C++ supports both procedural(step by step instruction)
and object oriented programming(using concept of classes and
objects).
a) Hiding part of program
b) Subdividing program into small independent parts
c)Overriding parts of program
d) Wrapping things into single unit
Answer: b
Explanation: Modularity means dividing a program into independent sub
programs so that it can be invoked from other parts of the same program
or any other program.
class A
{
int i;
public:
void
print()
{cout<<
"hello"
<<i;}
}
class B:
public A
{
int j;
public:
void
assign(
int a)
{j =
a;}
}
a) Abstraction
b) Encapsulation
c)Inheritance
d) Polymorphism
Answer: d
Explanation: As i and j members are private i.e. they are hidden from outer
world therefore we have used the concept of abstraction. Next data
members and there related functions are put together into single class
therefore encapsulation is used. Also as class B is derived from A therefore
Inheritance concept is used. But as no function is overloaded in any of the
classes therefore, the concept of polymorphism is missing here.
a) Member variables
b) Member functions
c)Class functions
d) Class variables
Answer:
b Explanation: Functions of a class are also known as member functions
of a class.
a) A reference cannot be made null
#include <iostream.h>
void func(void)
{
Cout<<("Hello");
}
void main()
{
func();
func( 2 );
}
Answer: a
Explanation: Boolean uses only 1 bit as it stores only truth values which can
be true(1) or false(0).
a) for
b) while
c)do-while
d) all of the mentioned
Answer: c
Explanation: do-while is called exit controlled loop because in do-while
termination condition is checked when we have executed the body of the
loop i.e. we are exiting the body and then checking the condition,
therefore, it is called exit controlled loop.
a) for
b) while
c)do-while
d) both while and for
Answer: d
Explanation: Both while and for loops are called entry controlled loop
because in both of them the termination condition is checked before we
enter the body of the loop hence they are called entry controlled loop.
#include
using namespace std;
int x[ 100 ];
int main()
{
cout << x[ 99 ] <<
endl;
}
a) Error in both C and C++
b) Outputs Hello twice in both C and C++
c)Error in C and successful execution in C++
d) Error in C++ and successful execution in C
Answer: a
Explanation: As the func(void) needs no argument during its call, hence
when we are calling func(2) with 2 as passed as a parameter then this
statement gives the error in both C++ and C compiler
a) Garbage value
b) 0
c) 99
d) Error
Answer: b
Explanation: In C++ all the uninitialized variables are set to 0 therefore the
value of all elements of the array is set to 0.
a) The object of that class
b) All members of a class
c)The public part of a class
d) The private part of a class
Answer: b
Explanation: A member function of a class can access all the members
of its class whether they are private, protected or public.