Passing by reference in C

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

    Because you're passing a pointer(memory address) to the variable p into the function f. In other words you are passing a pointer not a reference.

提交回复
热议问题