What is an Operator?

Operator defines which operation is to be performed on the variables. Different operators perform different kinds of operations.

Types of Operators:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operator
5. Conditional Operator
6. Increment and Decrement Operator
7. Bitwise Operators

What is a Virtual Function?

Virtual Function is a member function declared using the Virtual keyword in the Base class having same function name in the Derived Class as well. Virtual function implements the concept of Polymorphism in C++ programming language. To implement Run time polymorphism a pointer of base class is used. Compiler chooses at the run time the function to call by looking at the contents of Base class pointer rather than the type of pointer means that if it contains the address of the Base class object it will call member function of base class otherwise if it contains the address of Derived class object then it will call function of Derived class.

What is Operator Overloading?

Operator overloading is a technique in which an operator is used for performing multiple related operations. All the operators perform operations upon predefined data types of the C++, so in order to overload the operators these are used with the objects of class. Operator overloading implements compile time polymorphism in C++ as it performs multiple operations using a single operator.
Syntax of operator overloading:
Return_type operator# (arguments)
{
}
In the above syntax, return type is the type of value this function returns. Operator is a keyword which is used in operator overloading. # is the operator which we want to overload. Arguments are the objects passed to this function.

What are the advantages of Object oriented programming?

1. It provides reusability of source code by using Inheritance. This reduces the development time and cost.
2. It divides the problem into objects of real world.
3. Suitable for handling large and complex problems.
4. Provides data security by using Access Modifiers.
5. Easy to add new features within existing programs by using new objects.
6. It gives importance to data rather than functions and does not allow the data to be accessed (use) freely.

What are the Operands?

Operands are the variables on which the operation is to be performed.
For example, c= a + b
In above example, a and b are operands on which the operation has been performed.
+ is an addition operator.

What are the Logical Operators?

Logical operators are those which return true or false according to the result of two expressions.

Logical Operators are:

1. Logical AND (&&) Return true if both the expressions are true else return false
2. Logical OR(||) Return true if one of the expressions is true and return false if both the expressions are false.
3. Logical NOT (!) It takes only one operand. Return true if value of operand is false and returns false if value of operand is true.

What are assignment operators?

Assignment operators are used to assign the values of variables.

Assignment Operators are:

  • Addition assignment(+=)
It adds the value of right hand side variable with left hand variable and assigns the resultant value to the left hand side variable.
  • Subtraction assigment(-=)
It subtracts the value of right hand side variable from left hand variable and assigns the resultant value to the left hand side variable.
  • Multiplication assignment(*=)
It multiplies the value of right hand side variable with left hand variable and assigns the resultant value to the left hand side variable.
  • Division assignment(/=)
It divides the value of left hand side variable by the value of right hand side variable and assigns it to the left hand side variable.
  • Assignment (=)
It assigns the value of right hand side variable to the left hand side variable.

What is a Conditional Operator?

Conditional Operator (?:) is also known as Ternary Operator which perform operations on three operands.

Syntax: ExpressionA? expressionB:expressionC

Here expressionA is evaluated first if it is true then expressionB will be evaluated where and if the value of expression1 is false then expressionC will be evaluated.

Eg: int a, b,c;

c=a>b? a:b;

In above example if value of a is greater than b then value of a will be stored in c else if value of b is greater than value of a then value of b will be stored in c.

What are decrement operators?

Decrement operators are used to decrease the value of variable.

Types of Decrement Operators:
1. Pre decrement operator: In pre decrement operator, value of variable is first decreased and then it is assigned to other variable.
Eg: int a=5, b;
b=–a;
Output:
a=5 b=4
2. Post decrement operator: In post decrement operator, value of variable is first assigned and then it is decreased.
Eg: int a=5, b;
b=a–;
Output:
a=5 b=5

What are cin and cout in C++?

Cout is used to print the output on the screen. It is used with an insertion operator <<. Cin is used to read the value form the keyboard. It is used with extraction operator>>. Both these cin and cout are present in header file iostream.h.

Eg: int i;

Cout<<”Enter value of i”;

Cin>>i;

Cout<<”Value of i is” <<i;