吾爱程序员:这里有好玩的游戏和软件
当前位置:首页C语言教程 → C语言中的有趣事实

C语言中的有趣事实

来源:网络 | 更新时间:2022-02-07 14:03:48
以下是关于 C 编程的一些有趣事实: 1) switch 语句的 case 标签可以出现在 if-else 语句中。
#include <stdio.h>

int main()
{
int a = 2, b = 2;
switch(a)
{
case 1:
;

if (b==5)
{
case 2:
printf("52cxydh");
}
else case 3:
{

}
}
}
输出 :
52cxydh
2) arr[index] 与 index[arr] 相同 的原因是,数组元素是使用指针算法访问的。
// C program to demonstrate that arr[0] and
// 0[arr]
#include<stdio.h>
int main() 
{
int arr[10];
arr[0] = 1;
printf("%d", 0[arr] );

return 0; 
}
输出 :
1
3)我们可以使用 '<:, :>' 代替 '[,]' 和 '<%, %>' 代替 '{,}'
#include<stdio.h>
int main()
<%
int arr <:10:>;
arr<:0:> = 1;
printf("%d", arr<:0:>);

return 0;
%>
输出 :
1
4)在陌生的地方使用#include。 让“a.txt”包含(“52cxydh”);
#include<stdio.h>
int main()
{
printf
#include "a.txt"
;
}
输出 :
52cxydh
5)我们可以通过在格式说明符中的 '%' 之后使用 '*' 来忽略 scanf() 中的输入
#include<stdio.h>
int main()
{
int a;

// Let we input 10 20, we get output as 20
// (First input is ignored)
// If we remove * from below line, we get 10.
scanf("%*d%d", &a);

printf( "%d ", a); 

return 0; 
}
 

最新文章

热点资讯

手游排行榜

CopyRight 2020-2030吾爱程序员

鄂ICP备2021004581号-8

本站资源收集于网络,如有侵权请联系我们:35492删除0109@qq.com