void main()
{
int i; printf("%d",i^i);
}

Options
- cannot compile
- 0
- Unexpected
- Runtime Error


CORRECT ANSWER : 0

Discussion Board
Explanation-

After compiling and running this program output is zero.
Here, int i; is auto variable. auto is the default for function or block variables. auto int i is same as int i. auto is default hence it is never used.

A default value of auto variable is unpredictable value or garbage value.
While running this code value of 'i' takes as zero.

While printing value of i^i. 0^0 =0.
Here, '^' is bitwise XOR or exclusive OR. Result is calculated using table of exclusive OR.
e.g void main()
{
int i=8,j=4;
printf("%d",i^j);
}
Output: 12

Sapna 02-17-2017 03:35 AM

zero

in c local variables are asigned with garbage value .but it is exor so lets take garbage value as 1 for example k then 1^1 is 0.so that it is 0.

jb 07-15-2016 03:16 PM

WHAT A WRONG ANSWER

The value must be defined before using it in C !!
The answer will be "Debug err"

Christopher 01-22-2015 09:40 PM

Too late here, of course it's 0..

...

rathelor 11-5-2014 10:48 AM

Unexpected,

as we have a valid - altough uninitialized - variable with some garbage value.
Plus: any decent compiler with high enough warning level would cry for that 'void main()'..

rathelor 11-5-2014 10:46 AM

i XOR i = 0

So even if i is not initialized (ie random value) ... result of i^i will be 0.
The answer is correct.

xx 10-30-2014 07:29 PM

Garbage value

If we doesnt initialize the variable it took's the Garbage Value

Suganya 10-12-2014 12:06 AM

correct answer

in c the default value will be assigned so the answer is 0


intrest 10-9-2014 02:39 AM

correct

answer is zero.becoz the default value auto variable is 0.whatever we declare a data its take as a auto varible.

rajapandian 10-7-2014 12:42 AM

my opinion

i think it is unexpected...
it gives the garbage value..

samir 07-9-2014 02:18 AM

answer d- runtime error

Come on, guys. It's Runtime error.
You didn't have initialized the integer variable i.

Federico 04-26-2014 01:56 PM

wrong answer!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

c does not assign a default value to a variable unless assigned. it shows a runtime error as i is not initialized.

edwig 01-6-2014 02:28 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement