Five Interesting Things You Don't Know You Can Do In A C Language Program???

1. You Can Run A C Program Without Header Files

        You can run a C Program without including header files like #include<stdio.h> & #include<conio.h> and by compiling this code you don't get any error or warning in your C program And your program also runs successfully giving the right output as expected.

NOTE: These tricks only works in the Turboo C++.
               Example:-
                       // Program Illustrating The Upper Fact

                                void main()
                                   {
                                        int num1,num2;
                                          clrscr();
                                         
                                             printf("Enter Two Values Whose Addition is needed: ");
                                             scanf("%d %d",&num1,&num2);

                                                printf("\n Sum Is: %d",num1+num2);
                                         getch();
                                   

                 Output:-

                              Enter Two Values Whose Addition is needed: 12 15
                               Sum Is: 27


2. Array[index] is same as index[Array]

           As all of us what is an array, it an variable which stores multiple values at multiple consecutive location where all values are of same datatype. And all the variables have a same name but different index number. 

  If i want to take values in an array or print values we use loop there we use ' arrayname[index] ' to get values at that location but probably you don't know that we can also use ' index[arrayname] ' instead of ' arrayname[index] ' . Wow is'n t strange let's see it in a program.


          Example:-
                           void main()
                              {
                                     int arr[5];   // We declared an array capable of storing five values
                                      clrscr();
                                          printf("\nEnter Five Values: ");
                                         
                                          for(int i=0;i<=4;i++)           // Getting values
                                            {
                                                 scanf("%d", &arr[i]);    // Instead of this i can also write
                                              // scanf("%d", &i[arr]);    // The output will be the same
                                            }
                                          for(int i=0;i<=4;i++)        //Printing Values
                                            {
                                                  printf("%d", arr[i]);
                                            //or printf("%d", i[arr]);
                                            }

                                         //To print particular index value
                                                 printf("%d", 2[arr]);

                                 getch();
                              }

          Output:-

                        Enter Five Values: 12 22 13 7 45
                        12 22 13 7 45
                        13


3. Did you Know if doesn't check condition 


     In C Programming ' if-else ' are well-known to everyone it is used to check condition. If condition evaluates true the statements respective to ' if ' executes else the ' else ' part executes. As you studied that ' if ' keyword checks condition but it was a lie to you, ' if ' does not check condition it checks only 0 and 1.
          Means ' if ' only check 1 and 0, if it receives 0 then condition becomes false or if it receives 1 then condition becomes true. Let's see a program illustrating this :-

             Example:-

                               void main()
                                 {
                                      int i=0;
                                       clrscr();

                                         if(i)           //As you see I can't given any condition but given ' i '
                                          {               // As ' if ' receives ' 0 ' as ' i ' value it becomes false
                                                 printf("%d", i);
                                           }
                                         else
                                           {
                                                printf("Here Else part get executed because ' if ' receives 0 condition                                                                           becomes false");
                                           }
                                         getch();
                                  }        

             Output:-

                    Here Else part get executed because ' if ' receives 0 condition becomes false

4. We Can Replace [] And {} In A C Program With :-


          As we know that we use curly braces({}) to show start and end of something and rectangular braces are used in array index like " arrayname[index] " we can replace them without get an error or warning in our program. We can use ' <%  %> ' instead of ' { } '  and ' <:  :> ' instead of ' [  ] '. WoW seems interesting let see this in a program :-

             Example:-

                               void main()
                                  <%
                                            int arr[] = {1,2,3,4,5};
                                              clrscr();

                                                 for(int i=0;i<=4;i++)
                                                   <%
                                                            printf("%d", arr<:i:>);
                                                   %>
                                               getch();
                                  %>

              As you see in above program we used the <% %> instead of {}  and   <: :> instead of [ ] but output comes as expected.

                Output:-

                       1 2 3 4 5


5. We Can Ignore Input In ' Scanf() ' By :-


              As you will know that in ' scanf ' we use format specifier to specify that how many values we want to take from the user, if we use two format specifier then we have to give two variable to hold the value. But we can ignore a format specifier by using ' * ' in between ' % & specifier' and the compiler does not give any error and warning by doing this. Let's see this in an example :- 

            Example:-

                               void main()
                                  {
                                      int num1;
                                        clrscr();

                                           printf("Enter a number: ");
                                            scanf(" %*d %d ", &num1);   // See This Line I Will Explain Later

                                           printf("\n Value is: %d ", num1);
                                      
                                     getch();
                                  }

             As you see in above program that we have used * in scanf and only gives a variable and does not get any error or warning.

            Output:-
                           Enter a number: 12
                           Value is: 12


                       As you get all the interesting fact about C Language if you have any problem regarding this comment below and Try this all program by yourself.

If you want Educational and Interesting Videos visit to my channel: How To Hack 
Share on Google Plus

About howtohack

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments: