Hello World With C
  • 1. Introduction
  • 1.1 Variable
  • 1.2 Data Types
Powered by GitBook
On this page
  • Our first C program
  • Exercise 1.1

Was this helpful?

1. Introduction

Next1.1 Variable

Last updated 3 years ago

Was this helpful?

Since you have opened this e-book, I assume you have decided to learn C programming. So going straight there. You will need three things to get maximum results from this free ebook of C programming.

  1. Computer with internet connection

  2. C compiler / IDE for programming practice

  3. Problem-solving mentality

The question may be, where do you get the second point C compiler? I would recommend using the online IDE (Integrated Development Environment) and C compiler . Then you can start practicing programming directly without downloading or installing anything. We will use to practice C programming in this C learning tutorial.

If you want, you can download and install it on your computer to practice C programming.

Our first C program

From this link, you will see three sections after opening the online coding environment in your browser.

Here the first section will show our files, the second section will show the code we have written and the last section will show the output of the program we have written. If you want, you can hide the first section by clicking on the icon next to the text Files. You will see that an edited section already contains a program. You delete the whole program there and re-type the C program from the code section given below.

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

You may be wondering what all the fuss is about. No reason to worry. Everything will be explained nicely. You can click the run button to run your program for now.

If your C program prints Hello World on the screen, then Congratulations!🥳 You have written your first C program.

Now let us understand the program line by line:

The first line contains #include <stdio.h> This is a preprocessor command. Through which we ask our compiler to add or include the file named stdio.h. These files are called header files. Here .h is the extension of the header file.

By compiling this line, the compiler will first include the <stdio.h> file before compiling the C program and then start compiling. The second line contains int main(). This is called the main function. All C programs have a main function. The main function starts and ends with a second bracket. This bracket will contain the code we wrote.

int main()
{
    //Our Code will be here
    
    return 0;
}

Our program has finished with return 0; . Whose job is to terminate the main function and return 0 value. We typedprintf("Hello World") on the next 4 lines of our program; Which is a function. The function of this function is to print something on the screen. In this case, he will print whatever is in the middle of the double quotation. As you can see, printf ("Hello World"); A semicolon is typed at the end. In C programming, a semicolon has to be given after completing each statement. E.g .: return 0; We also gave a semicolon after the statement. At the beginning of learning C, I would forget to give a semicolon , and only compile error would come.

Indentation As you can see, we started with #include , int main () and {}. And printf ("Hello World") and return 0; Before that, I typed with 4 spaces. This is called indentation. If you do not code in this way, the program will run, but if you do not have the habit of indentation, then you will be excluded from the programming interview. If you survive in any other way, you will have to listen to the boss and your team members will get in trouble while reading your code. So I would urge you to take this matter seriously enough. We have tried to use indentation correctly in all the examples in this ebook.

What we have learned in this chapter

  1. The C program starts with the main () function.

  2. At the end of the line of code; Is to be added.

  3. With printf() we can print and show something on the screen if we want.

  4. When it comes to programming, you should always keep in mind the intentions.

Exercise 1.1

Now check yourself to see how much you have learned. Write a C program that will print to the screen:

This is my second program 

Important Links: Online C Compiler:

Codeblocks software download link:

https://repl.it/languages/c
http://www.codeblocks.org/downloads
repl.it
repl.it
Codeblocks
https://repl.it/languages/c