Passing by reference in C

后端 未结 17 2229
梦如初夏
梦如初夏 2020-11-21 23:26

If C does not support passing a variable by reference, why does this work?

#include 

void f(int *j) {
  (*j)++;
}

int main() {
  int i = 20;         


        
17条回答
  •  醉梦人生
    2020-11-21 23:34

    p is a pointer variable. Its value is the address of i. When you call f, you pass the value of p, which is the address of i.

提交回复
热议问题