#include <iostream>
usingnamespace std;
int main()
{
unsignedshort x = 65535; // largest 16-bit unsigned value possible
cout << "x was: " << x << endl;
x = x + 1; // 65536 is out of our range -- we get overflow because x can't hold 17 bits
cout << "x is now: " << x << endl;
x = 0;
cout<<"byte size "<<sizeof(int);
for(int i = 0; i<65538; ++i)
{
++x;
cout<<x<<" ";
}
cin>>x;
return 0;
}
compiler output:
byte size
byte size
I would at the very least expect to see the x variable output before the byte size output -
Sometimes unpredictably it will print the x data as well.
compiler program output:
byte size
byte size (¿twice?)
> I would at the very least expect to see the x variable output before the byte size output
you print a lot, ¿what do you do in order to see the first lines?
BY FAR the most interesting evidence of an inverted universe is this example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main()
{
cout<<"stop";
short a(0);
cout<<"flag";
for (int i(0); i<0; ++i)
{
cout<<++a<<endl;
}
cout<<"flag2";
return 0;
}
as i added in the semantic flags ("stop", "flag", "flag2") the program output would NOT preint anything in between. not the loop
program output: stopflagflag2
int main()
{
cout<<"stop";
short a(0);
cout<<"flag";
for (short i(0); i>100; ++i)
{
//cout<<++a<<endl;
cout<<i<<endl;
}
cout<<"flag2";
return 0;
}
This will output
stopflagflag2but skip the loop entirely...
Then this works:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int main()
{
cout<<"stop";
short a(0);
cout<<"flag";
for (short i(1); i<=100; ++i)
{
//cout<<++a<<endl;
cout<<i<<endl;
}
cout<<"flag2";
return 0;
}
I think the error lie in the true/false conditions of the for loops (middle T/F). For instance I thought i<=100; ++i)
meant to iterate the loop to <=100. What I understand now is that it is an evaluation: if true iterate the stuff in {}, if its false--stop. If my loops were false at the outset, it wouldn't increment at all. Go figure.