在这里我们将看到一些有关 c 编程的有趣事实。如下所示。
有时某些 switch 语句的 case 标签可以放在 if-else 语句内。示例#include <stdio.h>main() { int x = 2, y = 2; switch(x) { case 1: ; if (y==5) { case 2: printf("hello world"); } else case 3: { //case 3 block } }}
输出hello world
数组[index]可以写成index[array]。原因是数组元素是使用指针算术访问的。 array[5] 的值为 *(array + 5)。如果像 5[array] 这样的顺序相反,那么也和 *(5 + array) 一样。
示例#include <stdio.h>main() { int array[10] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 110}; printf("array[5]: %d
", array[5]); printf("5[array]: %d
", 5[array]);}
输出array[5]: 665[array]: 66
我们可以使用 代替方括号 [,],使用 代替大括号 {,}。 ul>示例#include <stdio.h>main() <%int array<:10:> = <%11, 22, 33, 44, 55, 66, 77, 88, 99, 110%>;printf("array[5]: %d
", array<:5:>);%>
输出array[5]: 66
我们可以在一些奇怪的地方使用#include。这里让我们考虑文件 abc.txt 中包含“the quick brown fox jumps over the lazy dog”这一行。如果我们在 printf 语句之后包含该文件,则可以打印该文件内容。
示例#include <stdio.h>main() { printf #include "abc.txt" ;}
输出the quick brown fox jumps over the lazy dog
我们可以在 scanf() 中使用 %*d 忽略输入。示例#include <stdio.h>main() { int x; printf("enter two numbers: "); scanf("%*d%d", &x); printf("the first one is not taken, the x is: %d", x);}
输出enter two numbers: 56 69the first one is not taken, the x is: 69
以上就是有关c编程的有趣事实的详细内容。