- 2
#include <iostream> int main(int argc, char **argv) { std::cout << 25u - 50; return 0; }
What will the line of code below print out and why? #include <iostream> int main(int argc, char **argv) { std::cout << 25u - 50; return 0; }
5 Respostas
+ 2
Have you tried in your code playground? What does it outputs?
+ 1
Yes. When the ligne "cout << 25u - 50" is executed, the calculation "25u-50" is proceeded first, and by default, the result is stored in an unsigned int. So the result is max_int-25 = 4294967271.
If you wish to outpout '-25', you should first store the result of the calculation in a signed int, then print it. Like this :
#include <iostream>
using namespace std;
int main() {
signed int res=25u-50;
cout << res;
return 0;
}
+ 1
Or simply :
int main() {
int res=25u-50;
cout res;
return 0 ;
}
0
The answer is not -25. Rather, the answer (which will surprise many) is 4294967271, assuming 32 bit integers.
0
Using C++ Write a program that populates a LIST with random integers from 10-60, then calls a function that divides the list
into two (2) Lists. The function then should remove all values greater that 19 from the list and store them in a NEW
list