In this program, the val value will overflow if it is a 32-bit machine, since the integer size is 4 bytes. Now we have 2 types of values ββin mathematics, positive and negative, so for calculations with negative results we use the signed representations ie int or char in C.
Let's look at a char example, range -128 to 127, unsigned char range 0-255. He reports that the range is divided into two parts for a signed view. Thus, for any signed variable, if it crosses its range of values ββ+ ve, it goes into a negative value. As here, in the case of char , when the value exceeds 127, it becomes -ve. And suppose that if you add 300 to any char or unsigned char variable, what happens, it will flip over and start again from scratch.
char a=2; a+=300;
what value? now you know that the maximum char value is 255 (a total of 256 values, including zero), so 300-256 = 44 + 2 = 46.
Hope this helps
source share