以下是关于 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:
{
}
}
}
52cxydh2) 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;
}