ch3
ch3
11. Which operators cannot be overloaded? What is the difference between Binary operator
overloading erloading and unary operator overloading?
Ans : Some operator cannot be overloaded these are as follows:
1. Size of operator
2. Membership operator . (dot)
3. Pointer to member operator .* (dot and asterisk)
4. Scope resolution operator : :
5. Conditional Operator ? :
Difference between Binary and Unary operators:
1. Unary operators overloaded by member function do not returns any value.
2. Unary operators overloaded by member function do not take any argument.
3. If it is friend function, it takes only one argument.
1. Binary operators overloaded by member function returns a value .It generally return an object
2. Binary operators overloaded by member function take argument it may be an object.
3. If it is friend function, it takes two arguments.
14. What is a pointer?How to use it for Call by value and Call by reference? Explain.
Ans: Pointer is a variable that holds address of some other variable. Pointer variable differs from simple
variable with “* “ in front of variable eg . int *ptr is a pointer variable of type integer. These pointers
can be used instead of simple variables. While using pointer we handle two operators “ * ” and ” & ”.
These pointers can be used with functions also. Pointers can be used as an argument or these can be
used as return variables also.
In function call if simple variables are used as argument ,it is called as call by value.
In function call if pointer variables are used as argument ,it is called as call by reference.
eg
15. What are different string functions?
Ans: In C++ different string functions are used to handle strings i.e. bulky text data.
Some of the string functions are as follows:
1. strlen(): This function finds length of argument included in brackets .The argument may be a
string or it can be a variableof string type. It returns an integer number ,which is one more than total
number of characters in that string (null character occupies one character).
Eg. X=strlen(“shree”)
This makes x= 6
2. strcpy(): This function copies data from source into destination that are included as arguments in
brackets .If the source contents some data, it will be overwritten.The source argument may be a
string( spelling ) or it can be a variable of string type and destination argument is always a string type
variable. It do not returns anything.
Eg strcpy(name, “shree”)
This makes name=”shree”.
3. strcat():This function concatenates i.e. mixes two strings. The contents of source are added into
destination argument included in brackets .The source argument may be a string or it can be a
variableof string type, but the destination is always a string type variable. It never returns any value.
The length of destination increases.
Eg.strcat(name,”deshmukh”)
Will make name=”shree deshmukh”
4. strcmp() : This function compares two strings.and it returns theASCII difference between first
uncommen character in two strings. If both strings are equal,then it returns 0.
Eg int x= strcmp(“swati”,”swami”)
Will make x=8.the ASCII difference between “m”and “t”.
class one
{public:
friend void welcome() //welcome() defined in class one
{cout<<”wecolme to c++ program”;}
};
class two
{public:
friend void welcome(); //welcome declared as friend function in class two
};
class three
{
friend void welcome(); //welcome declare as friend function in class three
};
void main()
{
three ob1;
two ob2;
one ob3;
ob3.welcome(); //welcome() is defined only for class one still can be used by object of two three
ob2.welcome();
ob1.welcome();
}
18. What is inheritance? What are its different types? Explain any one
Ans : Inheritance:
1. Inheritance is one of the feature of C++ that allows to use member of one class in another class.
2. The original class is called as base class.
3. The class in which member of base class are used is called as derived class.
4. Only the public member of base class can be used in derived class. Private members cant be
inherited.
5. The public member from base class can be made either private or public in the derived class.
6. The general syntax of class derivation is:
Class derived class name : visibility lable base classname
19. What is Polymorphism? What is run time polymorphism and compile time polymorphism?
Ans: C++ Polymorphism means that a call to member function will cause a different function to be
executed, depending on the type of argument or object that invokes the function.
Sometime the function call is fixed (which function is to be called)before execution of program i.e. at the
compile time itself.this is also called as early binding or compile time polymorphism.