My friend recently gave his C++ oral examination and one of the questions asked by the invigilators was regarding incrementing a variable after it has been set to the maximum value in its range
To be specific, in his case the invigilator asked him the output of a variable of type int if initialized to 32765 and then incremented by 1
Sample Code
int i = 32765;
i++;
cout<<i;
Question: What is the output value of i ?
Now as we know the range for an integer in C++ is from -32,768 to 32,767 or from 0 to 65535
As per the official documentation in the Turbo C++ compiler
Integer data type
Variables of type int are one word in length. They can be signed (default) or unsigned, which means they have a range of -32,768 to 32,767 and 0 to 65,535, respectively
To demonstrate and verify the actual output, I quickly coded the program below
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
int i = 32765;
for(int j=5;j<10;i++)
{
j++;
cout<<i<<”\n”;
}
getch();
}
A screenshot of the output of the sample above is as under
This brings us to the conclusion that the variable is incremented until the maximum value of its range (32,767) and is then reinitialized back (-32,768) to the beginning of the range automatically in a circular fashion

The diagram above gives a graphical representation of what happens when an integer is incremented after being set to the maximum value in its range
Happy Coding

Interesting, I would have given a different answer if I got this question in an interview… Thanks Mate