Unit 1(OOPs C++ ) Sem2

Theory

Quiz 1

What is the output of this program?

#include < iostream >
using namespace std;
int main( )
{
char line[100];
cin.getline( line, 100, 't' );
cout << line;
return 0
}


a) 100
b) t
c) It will print what we give
d) None of the mentioned

*pending

What is the correct syntax of defining a namespace?
a) Namespace name{};
b) namespace name{};
c) namespace name{}
d) typedef namespace name{} NAME

namespace name{};

Identify the correct statement
Namespace is used to separate the class, objects.
Namespace is used to group class, objects and functions.
Namespace is used to mark the beginning of the program.
None of the above

Namespace is used to group class, objects and functions.

Where does a cin stops it extraction of data?
By seeing a blankspace
By seeing ()
Both a & b
None of the mentioned

By seeing a blankspace


Quiz 2

What is the output of the following program?

#include<iostream>
using namespace std;
class X
{
public:
    int x;
};
int main()
{
    X a = {10};
    X b = a;
    cout << a.x << " " << b.x;
    return 0;
}


Compiler Error
10 followed by Garbage Value
10 10
10 0

10 10

Which of the followings is/are automatically added to every class, if we do not write our own.
Copy Constructor
Assignment Operator
A constructor without any parameter
All of the above

All of the above

What is the Output of following program?


Compiler Error
Runtime Error
Constructor called

Compiler Error


Surprise Test

State whether the following statements are True or False about the characteristics of static data members.
i) Only one copy of a static member is created for the entire class and is shared by all the objects of that class, no matter how many objects are created.
ii) The static member variable is visible only within the class, but its lifetime is the entire program.
C
i-False, ii-True
i-True, ii-False
i-True, ii-True

i-False, ii-True

How many times ‘its a while loop’ should be printed?

int main()
{
int i = 1 ;
i = i - 1 ;
while(i)
{
cout<<"its a while loop";
i++ ;
}
return 0;
}


1
2
0
infinite

0

Which of the following is correct about class and structure?
class can have member functions while structure cannot.
class data members are public by default while that of structure are private.
Pointer to structure or classes cannot be declared.
class data members are private by default while that of structure are public by default.

class data members are private by default while that of structure are public by default.

int main()
{
int i=0,x=0;
for(i=1;i<10;i*=2)
{
x++;
cout<<x;
}
cout<<x;
return 0;
}


1234567899
12345678910
123455
12344

12344

Which of the following statements is correct in C++?
Classes cannot have data as protected members.
Structures can have functions as members.
Class members are public by default.
Structure members are private by default.

Structures can have functions as members.

While using an object as a function argument, a copy of the entire object is passed to the function in ………….. method.
pass-by-value
pass-by-reference
pass-by-variable
pass-by-function

pass-by-value

What should be output of below program
if use enter a = 5?

int main()
{
int a;
cin>>a; // user can enter any value
if (++a*5 <= 25)
{
cout<<"Hello";
}
else
{
cout<<"Bye";
}
}


Bye
Hello
Undefined
Compilation Error

Bye

Which of the following factors supports the statement that reusability is a desirable feature of a language?
It decreases the testing time.
It lowers the maintenance cost.
It reduces the compilation time.
Both A and B.

Both A and B.

In C++ Program, inline functions are expanded during __
Run Time
Compile Time
Debug Time
Coding Time

Run Time

What is correct about the static data member of a class?
A static member function can access only static data members of a class.
A static data member is shared among all the object of the class.
A static data member can be accessed directly from main().
Both A and B.

Both A and B.

……………. can be invoked like a normal function without the help of any object.
constant member function
private member function
static member function
friend function

friend function

What is output of program?

class Mycpp
{
int Mycpp()
{
cout<<"Constructor";
return 0;
}
};
int main()
{
Mycpp obj;
return 0;
}


Compilation Error
Constructor
0
Runtime Error

Compilation Error



The content uploaded on this website is for reference purposes only. Please do it yourself first.