小编xen*_*n20的帖子

使用void子函数更改main中的值

我遇到了这个问题:

#include <stdio.h>
void change_number(int *x);

int main()
{
   int x;
   printf("Enter the number x: ")
   scanf("%d", &x);
   printf("In the main program: x = %d\n", x);
   change_number(&x);
   printf("In the main program: x = %d\n", x);
   return 0;
}
void change_number(int *x)
{
   x = *x+3;
   printf("In the subroutine: x = %d\n", x);
}
Run Code Online (Sandbox Code Playgroud)

预期产量:

Enter the number x: 555
In the main program: x = 555
In the subroutine: x = 558
In the main program: x = 558
Run Code Online (Sandbox Code Playgroud)

两个笔记: …

c pointers void

1
推荐指数
2
解决办法
796
查看次数

标签 统计

c ×1

pointers ×1

void ×1