Skip to content

Pointers: &, *, and pass-by-pointer · ⁨指针:&、* 与按指针传参⁩

English

A problem from last lesson

  • Last lesson, a function got a copy of your number. Changing the copy did not change the original.
  • C copies every argument you pass to a function. So a normal function cannot change your variable.
  • To change it, the function needs the variable's address — where it lives in memory.

中文

上一课留下的问题

  • 上一课里,函数拿到的是你那个数字的副本。改这个副本,不会改到原来的变量。
  • C 会复制你传给函数的每一个参数。所以普通的函数没办法改你的变量。
  • 要想改它,函数需要这个变量的地址 —— 也就是它在内存里待的位置。

x 在地址 0x100 处存着 5;指针 p 存着 0x100,所以 *p 取到 5

Handout

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩