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 the given C program code snippet:

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


The line int c = - -2; is evaluated as follows:

1. The expression `- -2` involves two consecutive negative signs. 2. The first negative sign (`-`) acts as the unary minus operator, and the second negative sign (`-`) is also a unary operator. 3. When two negative signs are used together, they effectively cancel each other out, so `- -2` becomes `2`.

Therefore, the variable `c` is assigned the value `2`.

The output of the `printf` function will be: 2

This Question Belongs to C Program >> C Miscellaneous

Join The Discussion

Comments (1)

  1. Manish Manish
    Manish Manish:
    10 months ago

    this options is not currect because we know that - - is the decrement operators so write answer is 1

Related Questions on C Miscellaneous