Let's assume the largest number an int
variable can hold is 10
. Consider the following situation:
main()
{
int r1 = 10;
int r2 = 1;
int x = r1 + r2;
}
According to my current little knowledge, r1 + r2
expression creates a temporary variable to hold the result before copying that value to x
.
What i want to know is since the largest x
can hold is 10
, i know (it's a guess actually) that if i print x
, i get 10
. But what about r1 + r2
?. Does this temporary variable that represent the result of r1 + r2
expression also hold 10 ?.
In other words does this temporary variable also has a largest it can hold ?
This is probably a noob question and i apologise.
Please Note:
I asked this question based on what i thought what overflowing is. That is; i thought when a variable reach to a state where (let's say for an integer case), if i add one more integer to it's value it's gonna overflow. And i thought when that happens the maximum value it holds gonna stay the same regardless of me increasing it. But that's not the case apparently. The behaviour is undefined when overflow for most types. check @bolov's answer