A Simple Problem

1
2
3
4
5
6
#include<iostream>
using namespace std;

int main()
{cout<<-1*2*sizeof(double);
cin.get();}


I want to get the result of "-16" and insisted on using sizeof(double)
but why the program gives me a strange number of 4294967280

Why did it become so strange?
Thank you.
because sizeof returns an unsigned value so you have -16 unsigned which means MaxUnsignedNumber-16 as the value wraps around, try with cout << signed( -1*2*sizeof(double) );
Last edited on
Topic archived. No new replies allowed.