📜  C编程有趣的事实

📅  最后修改于: 2021-05-25 22:51:07             🧑  作者: Mango

以下是有关C编程的一些有趣的事实:

1) switch语句的case标签可以出现在if-else语句内部。

#include 
  
int main()
{
    int a = 2, b = 2;
    switch(a)
    {
    case 1:
        ;
  
        if (b==5)
        {
        case 2:
            printf("GeeksforGeeks");
        }
    else case 3:
    {
  
    }
    }
}

输出 :

GeeksforGeeks

2) arr [index]与index [arr]相同
之所以起作用,是因为使用指针算法访问了数组元素。

// C program to demonstrate that arr[0] and
// 0[arr]
#include
int main() 
{
    int arr[10];
    arr[0] = 1;
    printf("%d", 0[arr] );
      
    return 0;    
}

输出 :

1

3)我们可以用'<:,:>’代替'[,]’,用'<%,%>’代替'{,}’

#include
int main()
<%
    int arr <:10:>;
    arr<:0:> = 1;
    printf("%d", arr<:0:>);
  
    return 0;
%>

输出 :

1

4)在奇怪的地方使用#include。
让“ a.txt”包含(“ GeeksforGeeks”);

#include
int main()
{
    printf
    #include "a.txt"
    ;
}

输出 :

GeeksforGeeks

5)我们可以通过在格式说明符中的’%’之后使用’*’来忽略scanf()中的输入

#include
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;     
}
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。