#include int main() { char a = 250; int expr; expr= a + !a + ~a + ++a; printf(“%d”, expr); return 0; } What will be output when you will execute following c code?

#include

int main()

{

char a = 250;

int expr;

expr= a + !a + ~a + ++a;

printf(“%d”, expr);

return 0;

}

What will be output when you will execute following c code?

A. -6

B. 5

C. 4

D. Another

Hướng dẫn

Chọn A là đáp án đúng

Xem lời giải

Xem lời giải

Biến char a = 250 vượt ra khỏi dải (-128 đến 127). Nên a = 250%256 = -6 (xem thêm: ) Trong các toán tử trong phép toán. Toán tử ! ~ ++ có cùng độ ưu tiên, nhưng trình tự kết hợp từ phải sang trái. Do vậy, ++a = -5 được thực hiện trước. expr = -5 + !(-5) + ~(-5) + (-5) = -5 + 0 + 4 -5 = -6

 

Thư viện tài liệu12 Tháng bảy, 2023 @ 3:00 chiều

Đánh giá chủ đề này
How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site