Interesting Facts in C Programming
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.
// 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 ‘{,}’
#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; // 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; } |
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Py-Facts - 10 interesting facts about Python
- Interesting Facts about C#
- Interesting Facts about C++
- Interesting facts about C Language
- Interesting Facts about Ubuntu
- Interesting Facts about Linux
- C++ bitset interesting facts
- Interesting Facts About Java
- Interesting facts about switch statement in C
- Interesting Facts about Macros and Preprocessors in C
- Interesting facts about Fibonacci numbers
- Interesting facts about strings in Python | Set 1
- Interesting facts about null in Java
- Some Interesting facts about default arguments in C++
- Interesting facts about Array assignment in Java



