0
#include <iostream>
using namespace std;
int main()
  {

    int i=10, j=5;
    int modResult;
    int divResult;
    modResult = i%j;
    cout << modResult;
    divResult = i/modResult; 
    cout << divResult;
    return 0;
}

I can't understand the code above. I got this one from my referral book in debugging exercise. I have debugged the program. But I can't Understand what is it and how it works so plz help.

amagain
  • 2,042
  • 2
  • 20
  • 36
Harsh patel
  • 445
  • 5
  • 11

1 Answers1

2

In the above program, you've imported iostream, which is a header file that is part of the C++ standard library. You can have a look at this answer if you want to know why using namespace std is used in your code. int main() is a function that has a return type of an integer.

You've declared two integers i and j which store 10 and 5 respectively. 'modResult' and 'divResult' are two pre defined integers where you can store computed values during program execution.

modResult stores the reminder of the result 10/5, which is zero as the reminder is 0 in this case.

divResult stores the quotient of the result 10/5, which is 2 in the case you divide i by j i.e. i/j but i divided by modResult is the case of infinite.

These two values are printed using cout>> statement.

Good luck with your learning C++. :)

amagain
  • 2,042
  • 2
  • 20
  • 36