Get the App
SLTechnology News&Howtos  ›  Servers  › 

[C language interview questions] question 1: the worthwhile conversion of signed and unsigned variables

Shulou Source: shulou.com Published: 2022-06-03 07:25:09 10月02日 Update

# include char getChar (int x pencil int y) {char c; unsigned int a = x; (a + y > 10)? (C = 1): (c = 2); return c;} int main (void) {char C1 = getChar (7prime4); char c2 = getChar (7Laurent 3); char c3 = getChar (7Mae Laurel 7); char c4 = getChar (7Marelle 8); / / C1 = 1 printf ("C1 =% d\ n", C1) / / c2 = 2 printf ("c2 =% d\ n", c2); / * c3 = 2 unsigned type and signed type are operated, * signed type is implicitly converted to unsigned type *-7 converted unsigned value plus 7 happens to overflow, the result is 0 * / printf ("c3 =% d\ n", c3) / * c4 = 1 *-8 the converted unsigned value plus 7 becomes a very large integer (the difference of 1 will overflow) * / printf ("c4 =% d\ n", c4); return 0;}

Tags: Symbols types variables integers results overflows operations languages Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn MariaDB Linux Docker