+ 1
In a program of sum of two input number in c . When i give only one input it assign automatically second no by 8.why?
2 Answers
+ 3
This occurs because with you declare a variable and don't initialize. The variable have a garbage value because you are using a space in memory that already have something.
Why is 8? I do no this is undefined behavior.
Just initialize your variables before do anything. It's good practice and prevents to happen bugs that can happen with garbages values
Edit: You can see more of this effect if you don't pass anything in your code. For me printed 0 and 8. You can think 0 happens because if you pass nothing it will set to 0 and i say nops it's really undefined behavior.
+ 3
Anya is right..Another good reason to initialize your pointers as "nullptr" if you dont have a use for them beforehand....