Vidyalelo
C Programming · Q8

C Miscellaneous

Programming · C Programming · question 8

Q8

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

A.
1
B.
-2
C.
2
Answer
D.
Error

Answer: Option C

Solution

Answer: Option C
Solution:
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