Loop Control Statements in C Introduction to HTML How to use the Github API The image tag, anchor tag and the button tag Ordered and Unordered Lists in HTML The division tag HTML Forms Tables in HTML Introduction to C Programming Introduction to Python Varibles and Datatypes in Python Operators in Python Typecasting in Python Input and Output in Python If Else in Python Loops in Python Break, Continue and Pass in Python Python practice section 1 Lists in Python Tuple in Python

Introduction to C Programming

C was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, protocol stacks, though decreasingly for application software. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

What is a header file?

These files contain the full implementation to various inbuilt functions we use in C. For now, think of it as a store of food items. Whenever you want to cook something, you don't need to manufacture each and every item, you just buy it from the store and use it. We have different stores for various needs. Similarly, we have various header files to perform various tasks in C. In C,we use the < stdio.h > header file to handle input and output to the screen. We can include it in our C program as:

    #include <stdio.h>
    

The main() function

Think of the main function as an entry point from where the execution of a C program starts. Like whatever we put on gas starts cooking, whatever we write inside the main function starts executing. Now, we will discuss about functions in much more details in future articles. For now, whatever we want our C program to do, we write it inside the main function. Now every block in C must be enclosed by curly brackets.

    #include <stdio.h>
    void main()
    {
        Write your code here.
    }            
    

Writing our first C program

Now, that we know the basics of C. Lets write a program that prints Hello World on the screen. To print a statement, we use the printf function which is defined in <iostream.h>. Every ststement must end with a semicolon. So,we write our program as follows:

    #include <stdio.h>
    void main()
    {
        printf("Hello World");
    }   
                

Output


    Hello World
                
And now, when we run the above program, we get Hello World as output!

Comments

Comments are notes that we write for ourselves in the program. They are not considered as part of the program on compilation. They are used to increase the readability of our program. They are of two types:-
  1. Single line Comments(//)
  2. Multi line Comments(/* ---- */)
Consider the following example.

    #include <stdio.h>
    void main()
    {   
        //This is my first program in C.
        printf("Hello World");
        /* Output is:-
            Hello World    */
    }    
    

Output


    Hello World