Technology Inside Out!

Index ¦ Archives ¦ Atom ¦ RSS

Getting Started With C language

Introduction to C language

C language is a middle level language developed by Dennis Ritchie in 1969 and the most secure OS "UNIX" is also coded in C language. It has just turned the world of Coding giving new level to programming, and introducing us to what is called "Structured Programming".

It is very important to note here that C is a Case Sensitive language, what this means is, TgW , tGw, TGw are all different. Don't worry if it's sound confusing, you'll be able to understand it better once we begin to learn about Variables.

Wait! before we start, the question arises :-

Why learn C language?

Well, learning C language would improve your logical skills, and many programming languages are directly or indirectly derived from C. This means, if you learn C language, you can learn other programming languages like C++, Java, JavaScript, Python, PHP, Perl and many others, much faster and it would be simple for you.

Pre Requisites for this and the coming Tutorials :-

To compile the C language programs, you need something called compiler. It doesn't matter if you're using Linux, Windows, or Mac, you'll surely get a C compiler. If you're Windows user, get the best compiler from the start ie gcc compiler. I wouldn't recommend any other like Turbo C etc. they are not good when compared to gcc. Download gcc compiler from here :-
http://gcc.gnu.org/
If you're on Linux you'll probably already have gcc compiler installed. To check if you have gcc compiler already installed please type the following command in the terminal

$ g++ -v

If you've gcc installed, you'll get something like this, as in my terminal window.

checking for gcc compiler in linux

Much of theory, isn't it? Ok, let's get started with some code.

First C Program

#include<stdio.h>

int main()
{
printf("Hello World");
}

Just compile it in your gcc compiler and you'll get Hello World printed in the output console.

If you need help in compilation and execution, wait for one more tutorial.

Now, we'll just break down each and every part of the program and analyse it.
``

#include<stdio.h>

``In this command, we ask the compiler to include a file (known as header file) which contains some pre defined fuctions which are needed to run the program.
We, request to add file stdio which is Standard Input/Output console file, as we need to display the print on the output console.
"#" (hash/pound) symbol here represents the pre-processor directive ie command started with a # sign goes to the pre-processor, means these statements are carried out first, before the program goes for compilation.

main()

This is a function in programming language, they are just meant to divide the program into modules. The main function of any program is of uttermost importance, as the program execution starts from main function.

printf()

This is also a function, it is the standard output function defined under stdio header file. Whatever we give in the paranthesis between the quotes is printed on the screen.

Note, that we have used int before main function , this means that this function would return a value of int type, and that's the reason we have given return 0 at the end.

Also note, that each statement in C would terminate with a semicolon. If you forget to put a semicolon, compiler would report an error.

You can now continue to Learn about variables in C

© The Geeky Way. Built using Pelican. Theme by Giulio Fidente on github.

Disclaimer Privacy policy