ExamVeda
Login
Home
This question belongs to C Program C Miscellaneous
C Miscellaneous
?

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

Answer & Solution
Correct Answer: Option C
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
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Manish Manish
Manish Manish 2 years ago
this options is not currect because we know that - - is the decrement operators so write answer is 1