Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

# 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;}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report