
在这里我们将看到一些有关 C 编程的有趣事实。如下所示。
有时某些 switch 语句的 case 标签可以放在 if-else 语句内。
示例
#include 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
#include 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 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 main() <%int array = ;printf("array[5]: %d", array);%>
输出
array[5]: 66
我们可以在一些奇怪的地方使用#include。这里让我们考虑文件 abc.txt 中包含“The Quick Brown Fox Jumps Over The Lazy Dog”这一行。如果我们在 printf 语句之后包含该文件,则可以打印该文件内容。
示例
#include main() { printf #include "abc.txt" ;}
输出
The Quick Brown Fox Jumps Over The Lazy Dog
我们可以在 scanf() 中使用 %*d 忽略输入。
示例
#include 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编程的有趣事实的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444506.html
微信扫一扫
支付宝扫一扫