Interesting Facts in C Programming
Last Updated :
11 Sep, 2023
Below are some interesting facts about C programming:
1) The case labels of a switch statement can occur inside if-else statements.
#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.
#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 ‘{,}’
#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”);
#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
#include<stdio.h>
int main()
{
int a;
scanf ( "%*d%d" , &a);
printf ( "%d " , a);
return 0;
}
|
Share your thoughts in the comments
Please Login to comment...