c语言中没有返回值的函数和不含形参的函数
001、没有返回值的函数
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c ## 测试c程序 #include <stdio.h> void put_star(int a) // 定义不含返回值的函数 { while(a-- > 0) putchar('*'); // 函数中没有return语句 } int main(void) { int x; printf("x = "); scanf("%d", &x); put_star(x); putchar('\n'); return 0; } [root@PC1 test]# gcc test.c -o kkk ## 编译测试 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk x = 3 *** [root@PC1 test]# ./kkk x = 7 *******
002、没有形参的函数
[root@PC1 test]# ls test.c [root@PC1 test]# cat test.c ## 测试c程序 #include <stdio.h> int get_pos_num(void) // 定义没有形参的函数 { int a; do { printf("please input an positive number: "); scanf("%d", &a); if(a <= 0) { puts("the value of a should be positive."); } } while( a <= 0); return a; } int main(void) { int x; printf("x = %d\n", get_pos_num()); // 没有形参的函数调用, 函数调用运算符中不需要任务内容 return 0; } [root@PC1 test]# gcc test.c -o kkk ## 编译 [root@PC1 test]# ls kkk test.c [root@PC1 test]# ./kkk ## 测试 please input an positive number: -86 the value of a should be positive. please input an positive number: 0 the value of a should be positive. please input an positive number: 533 x = 533
。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2023-11-09 非root 用户安装perl模块
2023-11-09 Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5
2023-11-09 Warning: prerequisite Test::More 0 not found.
2022-11-09 使用 gff2bed 将 gff文件转换为bed格式
2022-11-09 /usr/bin/ld: cannot find -lm
2022-11-09 File "/usr/bin/yum", line 30
2020-11-09 linux系统中磁盘容量配额