+ 1
Why is the output of the program is 0.
#include <iostream> using namespace std; int main() { int x; int y=2; cout<<x%y; return 0; }
1 Answer
+ 14
It seems SL compiler sets variable x (which is uninitialized) to 0. So, 0 % 2 gives you 0.
But it's a good practice to initialize your variable to something meaningful. (e.g. int x = 0;)