[go: up one dir, main page]

0% found this document useful (0 votes)
12 views6 pages

C Assignmentce6

The document contains a series of C++ programming questions and exercises covering topics such as classes, constructors, destructors, operator overloading, and differences between C and C++. It includes code snippets and asks for outputs, definitions, and explanations of concepts. The document serves as an assignment for understanding fundamental C++ programming principles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

C Assignmentce6

The document contains a series of C++ programming questions and exercises covering topics such as classes, constructors, destructors, operator overloading, and differences between C and C++. It includes code snippets and asks for outputs, definitions, and explanations of concepts. The document serves as an assignment for understanding fundamental C++ programming principles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

C++ Assignment -1

1)
class date
{
private : int day, month, year;
date()
{
day = 25;
month = 9;
year = 2000;
}
};
main()
{
date today;
}

2) main()
{
int a=9;
int k=10;
int &r=a;
cout<<r ;
r=k;
cout<<r ;
}
What is the output of the above code?

3) ______ means that both the data and the methods which may access it are defined
together in the same unit

4) A __________ helps to perform member wise initialization.

5) A Copy Constructor takes _______________ arguments.

a) 0 b) 1 c) 2 d) 3

6) A destructor takes _______________ arguments.

a) 0 b) 1 c) 2 d) 3
7) Write the syntax for copy constructor.

8)
int sum(int a, int b=5, int c=10);
main()
{
cout<<sum(5)<<endl<<sum(10,5)<<endl<<sum(5,10,10);
}
int sum(int a, int b, int c)
{
return a+b+c;
}
What is the output of the above code?

9) class Test
{
public:
int x;
mutable int y;
Test() { x = 4; y = 10; }
};
int main()
{
const Test t1;
t1.y = 20;
cout << t1.y;
return 0;
}

10) A function with the same name as the class, but preceded with a tilde character (~)
is called __________ of that class.

a) constructor

b) destructor

c) function

d) object

11) How many times a constructor is called in the life-time of an object?

a) only once b) Twice c) Thrice d) Depends on the way


of creation of object

12) Destructors can be overload(true/false) ?


13) #include<iostream>
using namespace std;
class A
{
A()
{
cout<<”Constructor”<<endl;
}
~A()
{
cout<<”Destructor”<<endl;
}
};
main()
{
A obj1;
}

14) #include<iostream>
using namespace std;
class A
{
int cash,gold;
public: void get_data()
{
cout << cash << " "<< gold << endl;
}
};
main()
{
A f1={10,20};
f1.get_data();
}

15) List at least 3 operators that cannot be overloaded only by friend functions .

16) What is the difference between new and malloc?

17) Difference between Member Function vs Friend Function ?

18) what are the default member functions are provided by compiler in a class?
19) For overloaded function, the compiler chooses the right specific version on the
basis of the parameter, is

a) type b) order c) number d) all

20) Difference between Reference Variable vs Pointer .(3 Marks)

21) Size of an object is equal to_____

A) size of data members only

B) size of members functions only

C) sum of sizes of data members and member functions

D) none of the above.

22) #include <iostream>


using namespace std;
namespace first{
}
int a = 4;
}
int main ()
{
int a = 16;
first::a;
cout << a;
return 0;
}
The output of the above code is ____

23) Why reference is not same as a pointer?

A) A reference can never be null

B) A reference once established cannot be changed.

C) Reference doesn't need an explicit dereferencing mechanism.

d) All of the above.


24) #include<iostream>
using namespace std;
namespace A
{
int var = 10;
}
namespace B
{
double var = 8.5;
}
int main ()
{
int a;
a = A::var + B::var;
cout<<”a=”<<a<<endl;
return 0;
}

25) Difference between C and C++ ?

26) What are the features available in C++?

27)The operator >> is called______________.

28) The operator << is called______________.

29) _____________ an operator, which is used to access global version of


data.

30) Difference between Malloc and New?

31) what is meant by Function overloading ?

32) Advantages of default Arguments ?

33) what are the C++ access specifiers?

34) Difference between structure in c vs structure in C++?


35) Difference between structure in c++ vs class in C++ ?

36) what is meant by class?

37) Can I create new operators using operator overloading?

a) Yes
b) NO

38) what is meant by Constructor ?

39) Types of Constructor

40) difference between shallow copy and Deep copy?

41) difference between Assignment operator overloading vs copy constructor?

42) What is meant by operator overloading?

43) write a syntax of Overload pre-increment operator(++) as a member


function

44) write a syntax of Overload pre-increment operator(++) as a Friend


function

45) write a syntax of Overload post-increment operator(++) as a member


function

46) write a syntax of Overload post-increment operator(++) as a Friend


function

47) Overloaded operators only through member function :

48) Operators that can be overloaded only by friend function?

49) Operators that cannot be overloaded by member function

50) Operators that can't be Overloaded

51) The function that can not modify the object that invokes it, is said to be-----------

You might also like