Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#1: Run the following commands in a program and observe the result. Turn in a wr

ID: 3663705 • Letter: #

Question

#1: Run the following commands in a program and observe the result. Turn in a written description of what was output, as well as an explanation of why the values output were produced. but can you explain why those are my outputs?

      int w = 2147483648;

      cout << w-1 << endl;

      cout << w << endl;

      cout << w+1 << endl;

      cout << w+2 << endl;

      unsigned u = 4294967296;

      cout << u-1 << endl;

      cout << u << endl;

      cout << u+1 << endl;

      cout << u+2 << endl;

Explanation / Answer

Integeger in CPP ranges from -2,147,483,648 to 2,147,483,647

We will be getting these outputs:

2147483647 //This is simple subtraction
-2147483648 //It is negative because this exceeds the normal int range in cpp

-2147483647 // On adding 1, this will reach to the end of the integer range.
-2147483646 // On adding 2, the same case will happen

Unsigned int ranges from 0 to 4,294,967,295

4294967295 // This is simple display after subtraction
0 // Since the unsigned range is till 295, on displaying it will again behave cyclic and show zero.
1 // Again, think of it as cyclic
2 // same as case I