基本編 - Hello, World!
難易度: 🟢 初級
所要時間: 10分
最初のプログラム
int main() {
println("Hello, World!");
return 0;
}
実行方法
# インタプリタで実行
./build/bin/cm run hello.cm
# コンパイルして実行
./build/bin/cm compile hello.cm -o hello
./hello
printlnの使い方
int main() {
const int x = 42; // 変更しない値はconstを使用
println("The answer is {}", x);
const string name = "Alice"; // 文字列もconstで不変に
const int age = 25; // 年齢も変更しない
println("{} is {} years old", name, age);
return 0;
}
重要(v0.11.0以降): 変更しない変数には必ずconstをつけます。これによりコンパイラが最適化を行いやすくなり、コードの意図も明確になります。
最終更新: 2026-02-08