执行以下程序后,输出结果是______。 #include <stdio.h> void fun(int a,int b,int c) { c=a*b; } void main() { int c=4; fun(2,3,c); printf("%d\n",c); }
时间: 2024-04-02 08:32:49 浏览: 41
执行该程序后,输出结果是 `4`。
原因是在函数 `fun()` 中,虽然将 `a` 和 `b` 的乘积赋值给了 `c`,但这里的 `c` 是函数 `fun()` 的局部变量,与 `main()` 函数中的 `c` 不是同一个变量。因此,`fun()` 函数中的赋值操作不会影响 `main()` 函数中的 `c` 变量的值。
相关问题
完成以下C语言代码功能:将主函数中输入的字符串反序存放。#include<stdio. h> #include<conio. h> #include(string. h> #define N 50 void fun(char *str, int n)
我可以提供一个示例代码:#include <stdio.h>
#include <string.h>int main ()
{
char str[100], temp;
int i, j; printf("输入一个字符串: ");
gets(str); j = strlen(str) - 1; for (i = 0; i < j; i++, j--)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
} printf("反序后的字符串: %s", str); return 0;
}
*定义函数实现n个字符串按字典顺序排序 开头: #include<stdio.h> #include<string.h> void fun (char *str[],int n)
好的,以下是一个实现n个字符串按字典顺序排序的示例代码:
```
#include <stdio.h>
#include <string.h>
void fun(char *str[], int n) {
int i, j;
char *temp;
// 使用冒泡排序算法
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (strcmp(str[j], str[j+1]) > 0) {
// 交换两个字符串的位置
temp = str[j];
str[j] = str[j+1];
str[j+1] = temp;
}
}
}
}
int main() {
char *str[] = {"apple", "banana", "orange", "grape", "kiwi"};
int n = sizeof(str) / sizeof(str[0]);
fun(str, n);
printf("排序后的字符串数组:\n");
for (int i = 0; i < n; i++) {
printf("%s ", str[i]);
}
printf("\n");
return 0;
}
```
在这个示例代码中,我们使用了冒泡排序算法对字符串数组进行排序。在排序过程中,我们使用了 `strcmp()` 函数来比较两个字符串的大小关系,并使用指针变量 `temp` 来交换两个字符串在数组中的位置。最后,我们输出排好序的字符串数组。
请注意,这个示例代码中的字符串数组是在程序中直接定义的。如果您需要从用户输入中获取字符串数据,请使用 `scanf()` 或其他输入函数来读取数据,并将它们存储在字符串数组中。
相关推荐
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)