Examveda
Examveda

Determine output:
void main()
{
      int c = - -2; 
      printf("c=%d", c); 
}

A. 1

B. -2

C. 2

D. Error

Answer: Option C

Solution(By Examveda Team)

In this C program, the expression - -2 involves the use of the unary minus operator (-) applied twice to the number 2.

- The first - operator negates the number 2, resulting in -2.
- The second - operator negates -2, which effectively makes it positive again, resulting in 2.

So, the variable c is assigned the value 2, and the output of the printf statement is c=2, which corresponds to Option C.

This Question Belongs to C Program >> Operators And Expressions

Join The Discussion

Comments ( 3 )

  1. 15TUIT011 ASHWIN
    15TUIT011 ASHWIN :
    6 years ago

    The answer given here is actually right. It's not the unary operator.Actually it is - (-2) and not --2.

  2. MITTU SHARMA
    MITTU SHARMA :
    6 years ago

    c is wrong option. because binary operator works on two operand. and unary operator works on single variale like ++a or --a.
    Dnt guide wrong and before post question's answer plz also execute and check.
    https://www.onlinegdb.com/online_c_compiler
    any one who are confused about that concept please check the code of program with run window.

  3. Hemendra Kumar
    Hemendra Kumar :
    8 years ago

    No. Answer is error. we cant have unary increment or decrement operator used on numbers directly. we can store the number in a variable and then increment or decrement it . Here it gives Compilation Error.

Related Questions on Operators and Expressions