Essential Operators(C++ Programming ) Questions and Answers

Question 1.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int a = 20;
6.
int b = 10;
7.
int c = 15;
8.
int d = 5;
9.
int e;
10.
e = a + b * c / d;
11.
cout
  1.    50
  2.    60
  3.    70
  4.    90
Explanation:-
Answer: Option A. -> 50

Explanation:In this program, the value e is evaluated by precedence ad we got the output as 50.
Output:
$ g++ ess4.cpp
$ a.out
50


Question 2.

Which operator is having the highest precedence in c++?


  1.    array subscript
  2.    Scope resolution operator
  3.    static_cast
  4.    dynamic_cast
Explanation:-
Answer: Option B. -> Scope resolution operator

None.



Question 3.

What is the name of | operator?


  1.    sizeof
  2.    or
  3.    and
  4.    modulus
Explanation:-
Answer: Option B. -> or

| operator is used to find the 'or' of given values.



Question 4.

What is the associativity of add(+);


  1.    right to left
  2.    left to right
  3.    both of these
  4.    None of the mentioned
Explanation:-
Answer: Option B. -> left to right

None.



Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int a = 0;
6.
int b = 10;
7.
if ( a && b )
8.
{
9.
cout
  1.    true
  2.    false
  3.    error
  4.    None of the mentioned
Explanation:-
Answer: Option B. -> false

&& is called as Logical AND operator, if there is no zero in the operand means, it will be true


Question 6.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main ()
4.
{
5.
int a, b, c;
6.
a = 2;
7.
b = 7;
8.
c = (a > b) ? a : b;
9.
cout
  1.    2
  2.    7
  3.    9
  4.    14
Explanation:-
Answer: Option B. -> 7

We are using the ternary operator to evaluate this expression. It will return first option, if first 

condition is true otherwise it will return second
Output:
$ g++ ess1.cpp
$ a.out
7



Question 7.

What are the essential operators in c++?


  1.    +
  2.    |
  3.    All of the mentioned
Explanation:-
Answer: Option D. -> All of the mentioned

None.



Question 8.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main ()
4.
{
5.
int a, b;
6.
a = 10;
7.
b = 4;
8.
a = b;
9.
b = 7;
10.
cout
  1.    a:4 b:7
  2.    a:10 b:4
  3.    a:4 b:10
  4.    None of the mentioned
Explanation:-
Answer: Option A. -> a:4 b:7

In this program, we are reassigning the values of a and b because of this we got the output as a:4 b:7
Output:
$ g++ ess.cpp
$ a.out
a:4 b:7



Question 9.

In which direction does the assignment operation will take place? 


  1.    left to right
  2.    right to left
  3.    top to bottom
  4.    None of the mentioned
Explanation:-
Answer: Option B. -> right to left

In assignment operation, the flow of execution will be from right to left only. 



Question 10.

Pick out the compound assignment statement. 


  1.    a = a - 5
  2.    a = a / b
  3.    a -= 5
  4.    None of the mentioned
Explanation:-
Answer: Option C. -> a -= 5

When we want to modify the value of a variable by performing an operation on the value currently 

stored, We will use compound assignment statement. In this option, a -=5 is equal to a = a-5.