11
Interesting Facts In C Programming
C
Printf
Switch-statement
Include
Scanf
Arrays

C is a general-purpose, imperative computer programming language. Every programmer know the basic syntax of C Language.

I am here to share some Interesting Facts In C Programming which I came across reading till now. Some of these facts you may know already .

Lets See ..........

  • A switch statement's case labels can occur inside if-else statements or in loops.

          switch (x)  {  case 1:; // ...
    
          if (y==2)
          {
    
            case 2:;
            // ...
    
          }
    
          else case 3:
          {
            // ...
    
            for (b=0;b<10;b++)
            {
    
              case 4:;
              // ...
            }
          }
          break;
    
        case 5:
          // ...
          break;}
    
  • You can use #include in strange places :

     void main()   {
    
      printf
    
      *#include* "next.c"   }
    

And "next.c" contains :

      ("HackerEarth!\n");

It will print "Hackerearth".

  • Argument index specification in printf format specifier :

     *#include*  < stdio.h >
    
    void main()   {
    
      printf ( "%4$d  %3$d  %2$d  %1$d ",  1,  2,  3,  4);    }
    

It wil Print 4 3 2 1.

  • Ignoring input in scanf:

     *#include*  < stdio.h >
    
      void main()    {
    
        int a;
    
        scanf("%*d%d", &a);
    
        printf ( "%d ",  a);       }
    

If input is 4 5 => a will have value 5 .

  • Using range with switch cases

      switch(c) {
    
       case 'A' ... 'Z': //do something
    
         break;
    
             case 1 ... 5 : //do something         }
    
  • Printf in C allows you to use variables for formatting format specifiers themselves

     *#include*  < stdio.h >
    
       int main() {
    
          int a = 3;
    
           float b = 6.412355;
    
          printf("%.*f\n",a,b);
    
         return 0;            }
    

It will print => 6.412 .... if a=2 it will print => 6.41 .

  • a[index] is same as index[a]

      *#include*  < stdio.h >
    
        int main() {
    
           int a[10];
    
           a[0]=1;
    
           printf("%d", 0[a] );
    
         return 0;     }
    

It will print output = 1.

  • '<:, :>, <%, %>' in place of '[, ], {, }',

Earlier years when it was hard to write '[, ], {, }', C actually accepted '<:, :>, <%, %>' respectively .

int main() <%

    int a <: 5 :>;

    a<:0:>=1;

    printf("%d",a<:0:>);

    return 0;

%>

It will print output = 1.

  • main() is not compulsory.

     *#include*  < stdio.h >
    
      *#include* DIPAK m##a##i##n
    
       int DIPAK() {
    
           printf("HackerEarth.");     }
    

It prints => "HackerEarth".

That's It. Thank You for reading . If you know more facts about C you can comment below .

Please read ,share and don't forget to upvote . and refer my other notes here.

Author

Notifications

?