+1

Why it happen, when int b = b in bellow code??

There are no numeric value assign to "int b" so why cpp take b = 8 automatically, why not another? https://code.sololearn.com/c0jP67DATx79/?ref=app

4/12/2019 8:34:28 AM

Chatku Roy

4 Answers

New Answer

+2

Chatku Roy You are getting b = 8 on sololearn compiler, on some other compiler you may get b = 0 or any other random value. The rule is that any variable must be initialized before it's first use, till then it contains garbage value in int b = b; the variable b is not initialized before first use.

+2

Thank you "swim" I understand that.

+1

Because you are trying to assign an empty value to b. If you do this: Int b=5; Int c=b; It will be ok, just because i have assigned the same value of b to c (5 in this case). In your exercise this don't happen. So, try to assign an int value and then retry.

+1

Thank you Simone.