Determine Output:
void main()
{
int c = - -2;
printf("c=%d", c);
}
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
Join The Discussion
Comments (1)
Related Questions on C Miscellaneous
Determine output:
void main()
{
int const *p=5;
printf("%d", ++(*p));
}
A. 6
B. 5
C. Garbage Value
D. Compiler Error
A. mmm nnn aaa
B. mmmm nnnn aaaa
C. Compiler Error
D. None of These
A. I hate Examveda
B. I love Examveda
C. Error
D. None of These
Determine Output:
void main()
{
static int var = 5;
printf("%d ", var--);
if(var)
main();
}
A. 5 5 5 5 5
B. 5 4 3 2 1
C. Infinite Loop
D. None of These

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