Introduction To C Part 2.

Introduction To C Part 2.

Hi there, in Part one of the series of the introduction to C, I talked about the tools you need to get started with C. In this article, I'll be walking you through the basic C codes. So with that said, consider the lines of code below.

C Code

#include<stdio.h>
int main(void) {
printf("This is my first C program");
return 0;
}

Don't worry if you don't understand what you're seeing yet. I'll be explaining each line of code below.

Line 1: #include<stdio.h> is a header file library. Basically what it does is that it imports all the necessary functions you need in your program. For example, the printf() statement used above is a function and it is being imported from the header library file. So in simple terms, your program will not run if you don't have the necessary library files.

Line 2: int main(void) { // code } Every C program has a primary function that must be named main. This is where any code that you want to execute goes into. It usually controls program execution by directing the calls to other functions in the program.

Line 3: printf() is a function that lets you output/print output on the screen. As I said earlier, the printf() function will not work without including the header library file into the top of your file.

Line 4: return 0; means that the function doesn't return any value. It is used when the void return type is used with the function. It is not mandatory though.

And don't forget to close the curly braces when done with typing your code {}. Notice how I ended the Line 3 with a semicolon. That is how all lines of code in C must end. Now I want you to try that in your text editor and you let me know how it goes in the comments.

Until next time.

Peace.