下列程序的执行结果是( )。 void fun ( int *p ) { (*p)++; } main( ) { int a=5; fun(&a); printf("%d",a); } A. 5 B. a C. 6 D. 程序有误
时间: 2024-01-27 08:04:49 浏览: 109
执行结果是 C. 6。首先定义了一个函数 `fun`,它的参数是一个指向整型变量的指针。在 `main` 函数中,定义了一个整型变量 `a`,然后调用 `fun` 函数,并将 `a` 的地址作为参数传入。在函数中,将指针所指向的整型变量的值加 1,即 `(*p)++`。因此,在 `fun` 函数调用后,`a` 的值变成了 6。最后,使用 `printf` 函数输出 `a` 的值,结果为 6。
相关问题
下列程序的输出结果是 void fun(int *n){ while((*n)--); printf("%d",++(*n)); main() { int a=100; fun(&a);}
很抱歉,该程序存在语法错误,无法通过编译。以下是修正后的程序:
```
#include <stdio.h>
void fun(int *n) {
while ((*n)--);
printf("%d", ++(*n));
}
int main() {
int a = 100;
fun(&a);
return 0;
}
```
程序的输出结果为 101。在函数 `fun` 中,通过指针对参数 `n` 进行操作,使得 `n` 的值递减至 0,然后再将 `n` 的值递增 1,最终输出结果为 101。在主函数中,通过调用 `fun` 函数并传入参数 `a` 的地址,实现对变量 `a` 的修改和输出。
void fun ( int *p ) { (*p)++; } main( ) { int a=5; fun(&a); printf("%d",a); }
&a); }
This code defines a function named "fun" that takes a pointer to an integer as its argument. Inside the function, the dereferenced value of the pointer is simply accessed and not used in any way. The main function declares an integer variable "a" and initializes it to 5, then calls the "fun" function with the address of "a" as the argument. This code does not have any practical purpose and will not produce any output.
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)