Write Your First Program In C
· HEADER FILES
Header files consist standard functions which are essential to write our program. It is code which is already written in C so we can use it directly. Without declaring proper header file code will not run. At basic level we will use <stdio.h> (standard input output) to use this header file in our code we will use preprocessor directive ‘#include’. Preprocessor directive are the commands which start with ‘#’.
· Comments
Comments is the line or lines of the code which is not executed by the computer. Generally, comments are used for documentation purpose. Single line comments are denoted with ‘//’ for Ex. ‘//this is single line comment’
Multiline comments start with /* and ends with */
For example:
/*
This
Is
Multiline
Comment
*/
You will better understand concept and use of comment in further articles
· Main function
Main function contains the actual executable code the main function can be written in following ways.
· printf() function
printf() function is used to display the output of our code. printf() function is also known as formatted output function.
· Where to write your program?
If you have PC then you find plenty of videos to install C language in your PC on YouTube. You still have problem in installing you can simply go to google and search C compiler and open 1st site that you see. Don’t worry if you do not have PC you can still use some apps or online compilers which actually supports C language. At end of topic learning matters platform doesn’t.
Remember:
Every C file is saved with ‘.c’ extension.
· Your first program
Usually, the first program in any programming language is to display ‘Hello World!’ for that we need to use printf() function. In printf() function string is written in double quote (“”). In C language end of instruction semicolon (;) is used. For better understanding, when write sentences in English at end of statement you add full stop similarly, we use ; in C language after instruction.
Now, how computer will know what is printf() function? For that we will include header file first and this program is written in main function you can try all the method given above at your own.
By combining all of this let’s see how our first program looks like …
Output:
Congratulations you wrote your first code!...
Are you exited to do something more? You can try to write code to print your name as output .
Stay tuned for next post share with your friends and follow us on social media.
Subscribe to my newsletter
Read articles from Vibhas Thakurdesai directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vibhas Thakurdesai
Vibhas Thakurdesai
I am a FY Btech AIML student at kitcoek.