Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arithmetic operator return type

Tags:

c++

int main(int argc, char **argv)
{
    unsigned char a = 10, b = 100;
    std::cout<<sizeof(a-b)<<endl;
    return 1;
}

Output: 4

What is the return data type?

like image 271
Jacob Avatar asked May 07 '11 23:05

Jacob


1 Answers

Arithmetic is always performed at least with int precision in C++. a and b are both promoted to int and the result of the subtraction is of type int.

There are a set of rules used to determine the type used for an arithmetic operation; MSDN has a handy table listing the rules.

like image 123
James McNellis Avatar answered Sep 22 '22 19:09

James McNellis