Files
spl/stage1/test14_assignment.spl
2026-07-05 21:45:43 +08:00

57 lines
862 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* ===== 模块7高级特性 =====
* test14_assignment — 复合赋值
* 难度2/5
* 验证点:+= -= *= /= %= &= |= ^= <<= >>=
*/
fn main() i32 {
var x: i32 = 10;
/* += */
x += 5;
if x != 15 { ret 1; }
/* -= */
x -= 3;
if x != 12 { ret 2; }
/* *= */
x *= 2;
if x != 24 { ret 3; }
/* /= */
x /= 4;
if x != 6 { ret 4; }
/* %= */
var y: i32 = 17;
y %= 5;
if y != 2 { ret 5; }
/* &= */
var a: i32 = 0xFF;
a &= 0x0F;
if a != 0x0F { ret 6; }
/* |= */
var b: i32 = 0xF0;
b |= 0x0F;
if b != 0xFF { ret 7; }
/* ^= */
var c: i32 = 0xFF;
c ^= 0xF0;
if c != 0x0F { ret 8; }
/* <<= */
var d: i32 = 1;
d <<= 4;
if d != 16 { ret 9; }
/* >>= */
var e: i32 = 64;
e >>= 3;
if e != 8 { ret 10; }
ret 0;
}