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

52 lines
1.1 KiB
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.
/* ===== 模块1核心基础 =====
* test02_variables — 变量与常量声明
* 难度1/5
* 验证点var 声明 + 类型注解、var 声明 + 初始化、
* const 声明、var := 短声明、const := 短声明
*/
fn main() i32 {
/* var 带类型注解与初始化 */
var a: i32 = 10;
if a != 10 { ret 1; }
/* var 先声明后赋值 */
var b: i32;
b = 20;
if b != 20 { ret 2; }
/* const 声明 */
const c: i32 = 30;
if c != 30 { ret 3; }
/* var := 短声明(类型推断) */
var d := 40;
if d != 40 { ret 4; }
/* const := 短声明 */
const e := 50;
if e != 50 { ret 5; }
/* 多类型变量 */
var i8v: i8 = 127;
if i8v != 127 { ret 6; }
var u8v: u8 = 255;
if u8v != 255 { ret 7; }
var i16v: i16 = 32767;
if i16v != 32767 { ret 8; }
var u16v: u16 = 65535;
if u16v != 65535 { ret 9; }
var u32v: u32 = 4294967295;
if u32v != 4294967295 { ret 10; }
/* 指针类型变量 */
var x: i32 = 100;
var p: *i32 = &x;
if p == null { ret 11; }
ret 0;
}