Apr 26, 2015 at 1:18pm UTC
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int i;
float f;
double d;
long double ld;
unsigned int ui;
unsigned long int uli;
i=-5;
f=2;
d=3;
ld=3;
ui=6;
uli=4;
cout<<"\n sizeof long double.."<<sizeof(ld*d)<<'\t'<<ld*d;
cout<<"\n sizeof double.."<<sizeof(d*f)<<'\t'<<d*f;
cout<<"\n sizeof float.."<<sizeof(f*i)<<'\t'<<f*i;
cout<<"\n sizeof unsigned long int.."<<sizeof(uli*f)<<'\t'<<uli*f;
cout<<"\n sizeof unsigned int.."<<sizeof(ui*i)<<'\t'<<ui*i;
getch();
}
OUtupt displayed by the above program:
sizeof long double..10 9
sizeof double..8 6
sizeof float.. 4 -10
sizeof unsigned long int.. 4 8
sizeof unsigned int.. 2 65506
why this compiler last line assigned 65506 please explain...
Apr 26, 2015 at 1:22pm UTC
You're multiplying -5 * 6 and storing it in an unsigned integral type.
Apr 26, 2015 at 1:25pm UTC
Mr. Luke
thanks for your reply
But I have one doubt in particular line.
Why 65506 will printed?. Please look at above line multiply the same value and result is correct. Please explain
Apr 26, 2015 at 1:32pm UTC
In the line above you're multiplying 'uli' and 'f'. Then on your suspect line, you multiply 'ui' and 'I'. They aren't the same.
Anyhow, what were you expecting the result to be, -30? -30 is the signed representation of the number. The unsigned representation is 65506 which is printed out.