Back to Course返回课程

C Language Basics C 语言基础

Syntax, Operators, Control Flow & Arrays 语法、运算符、控制流与数组

Basic Structure基本结构

#include <stdio.h> int main(void) { // This is a comment printf("Hello World!\n"); return 0; }
  • #include: Imports libraries引入标准库
  • int main(void): Entry point程序入口点
  • return 0;: Success code程序成功结束

Data Types数据类型

int

Integers (whole numbers)整数

int score = 100;
double

Decimal numbers小数 (双精度)

double pi = 3.14159;
char

Single character单个字符

char grade = 'A';

Input / Output输入与输出

Printing (Output)输出 (Print)

int age = 20; printf("I am %d years old\n", age);

Format specifiers:格式占位符: %d (int), %lf (double), %c (char), %s (string)

Scanning (Input)输入 (Scan)

int number; scanf("%d", &number);

⚠️ Don't forget the & (address of) operator!不要忘记 & (取地址符)!