Open In App

Interesting Facts in C Programming

Last Updated : 07 May, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Below are some interesting facts about C programming:

1)

The case labels of a switch statement can occur inside if-else statements.

C
#include <stdio.h>

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

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

    }
    }
}

Output :

GeeksforGeeks

2)

arr[index] is same as index[arr] The reason for this to work is, array elements are accessed using pointer arithmetic.

C
// 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;    
}

Output :

1

3)

We can use '<:, :>' in place of '[,]' and '<%, %>' in place of '{,}'

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

    return 0;
%>

Output :

1

4)

Using #include in strange places. Let "a.txt" contains ("GeeksforGeeks");

CPP
#include<stdio.h>
int main()
{
    printf
    #include "a.txt"
    ;
}

Output :

GeeksforGeeks

5)

We can ignore input in scanf() by using an '*' after '%' in format specifiers

C
#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;     
}

Article Tags :

Similar Reads