Passing by reference in C

后端 未结 17 2456
梦如初夏
梦如初夏 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:48

    You're passing a pointer(address location) by value.

    It's like saying "here's the place with the data I want you to update."

提交回复
热议问题