Tutorial 1: Introduction to C Programming

Introduction
C was developed in 1972 by Dennis Ritchie based on a programming language called B (which is derived from BCPL language). It is one the most used programming language in software development area. At the beginning, C was designed and developed for the development of UNIX operating system. Today C has been widely used to develop many type of application software such as basic calculator, word processor, games, operating system etc.

Getting Started - New to C Language?
Before we discuss C syntax in details, we look at the fundamental stages of C program development. Typically there are four development stages namely editing, pre-processing and compiling, linking and executing.

Editing
Editing is the process of writing the C source code. Programmers write C source code using editor program. There are many editor program available for C. But two editors widely used on Linux platform are vi and emacs. On Windows platform, we can use Notepad as the editor program but most peoples use software package for C such as C++ Builder, Code::Blocks, Dev-C++, Microsoft Visual Studio etc. that have integrated editor. These software provides complete programming environment for writing, managing, compiling, debugging and testing C source code. This is also known as Integrated Development Environment (IDE).

Pre-processing and Compiling
A C source has to be translated into machine language code. Machine language is a language that computer can understand in the form of binary number. The process of code translation is called compiling. During compilation process, the compiler can detect any syntax error due to unrecognised program code as well as structural errors. The output of compilation process is an object code which is saved in a file called object file. In C, before a source code is compiled, there is a stage called pre-processing. During this stage, C pre-processor performs directives which are usually including header or other C files to be compiled and text substitution.

Linking
Linking is a process of combining generated object files, add required codes from C standard library and produce an executable file. C standard library is collection of header files. Header files contain C source code that performs common operation such as input/output, mathematical operation and string handling.

Execution
The execution stage is where you run the program to check whether it produce the desired output. This stage can be a testing stage where you check the output of your program. If it does not produces the suppose output, then you have made logic (semantic) error in your source code. Unlike syntax error, logic error won't be detected during compilation process. Therefore you have to find out the error's location by yourself.

C Program Layout
Basically, a C program consists of two sections:
1. pre-processor directives
2. main function



The pre-processor section is the place where we specify what compiler should do before compiling the source code. Usually we would specify the included header file which will be used in our program. A header file keeps all the information about functions available in standard C library. All pre-processor directives begins with the # symbol. The second section begins with the function main() definition. The function main() is where the program starts its execution. Thus function main() must present in any C program.

An Example of C Program
We begin by programming a very simple C program. Write the following program using your editor program. When you finish writing it, compile it and execute the program. You will get a text message displayed on your monitor screen. The program's output is given at the sample output section. Don't worry if what you type does not make sense. I'll explain everything later.
/* An example of C program */
#include <stdio.h>

/* main function definition */
int main()
{
 printf("C program example\n");
 return 0;
}
Sample output:

C program example

Explanation:

The first line of the program is
/* An example of C program */
This line is not actually part of the program. It is simply a comment and it is included to provide information on what the program does. A comment begins with /* and end with */. It is a good habit to include comments in every part of your program especially when you are writing a big program/project. It will keep you inform what are the code actually doing since you may not always remember what they do.

Then we have the next line which is
#include <stdio.h>
This is also not part of the program, but it is a very important line in C program. In fact, if this line is omitted, the program won't actually works. The symbol # indicates that this is a pre-processor directive. Remember about header file that I mentioned during compilation process. This line is a directive to the compiler to include stdio.h header file in our program. stdio.h contains information on input/output routines which will be needed during compilation process. In this case we are using the printf() function from stdio.h.

The next line is
/* main function definition */
This is also another comment line.

Then we have the main function section.
int main()
{
 printf("C program example\n");
 return 0;
}
The main function has only two (2) statements. The first is printf() statement and the second is return statement. I'll explain both statements in details later.

Now we look at the first line of function main() definition.
int main()
This defines the start of the function main(). Function main() has the keyword int signifies what type of value will be returned by the function. In this case the function main() will return an integer value. There parentheses following the main. This is the place where we specify information to be transferred to function main(). However, in this example we don't transfer any information.

Then we have
{
 ...
 ...
}
The open brace specifies the start of the function whilehe close brace specifies the end of the function. The portion within the braces is called block or body. Within the block is where we write the statements that defines what our program does.

Now lets look at the first statement.
 printf("C program example\n");
printf() function instructs the computer to display characters or a string enclosed by the qoutation marks on the monitor screen. A string is a combination of numerous characters. Items enclosed by the parentheses are called arguments.

The last statement in this program is
 return 0;
At the end of function main() we have to include return 0 statement because function main is defined to return a value of integer type. This statement also indicates that the program has terminated successfully.

Symbolic Constant - #define Directive
I would like to discuss another pre-processor directive that is usually used in C programming. #define directive is used to define a symbol (name) that represents a constant value. Basically #define directive acts as a constant converter. It causes the compiler to go through all the program's codes and whenever it encounters the defined symbol, it will substitute the symbol with the specified value. For example,
#include <stdio.h>

#define PI 3.14159

int main()
{
 ...
 ...
}
Symbol PI is defined and it represents the value of 3.14159.

35 comments:

Unknown said...

Welcome to the C Tutorial by C Experts. The objective of these tutorials is to provide in depth understanding of C language. In these tutorials Read more
Check this siteTeKslate for indepth C training.
Go here if you’re looking for information on C Training.

Unknown said...

Thanks for sharing such a great information..Its really nice and informative..
c programming training

Unknown said...

Very Useful information that i have found. donot stopand Please keep updating us..... Thanks

Sujitkumar said...

Nice info. Thanks for sharing info about about c language training. I want to learn c training this tutorial is really helpful. Thanks a lot. Keep updating tutorials……

TECHENOID said...

all of my doubt cleared in this blog post.thanks for this post

i am michael techenoid (http://www.techenoid.com)

sumathikits said...

nice article
http://www.kitsonlinetrainings.com/android-online-training.html
http://www.kitsonlinetrainings.com/blockchain-online-training.html
http://www.kitsonlinetrainings.com/data-science-online-training.html
http://www.kitsonlinetrainings.com/dot-net-online-training.html

sumathikits said...

Nice article thanks for sharing the great information ........!
splunk admin training

splunk development training

django training

business analysis training

Softgen Infotech said...

I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing.

Became an Expert In Google Cloud Platform Training in Bangalore! Learn from experienced Trainers and get the knowledge to crack a coding interview, @Softgen Infotech Located in BTM Layout.

Bangalore Training Academy said...

Your topic is very nice and helpful to us … Thank you for the information you wrote.

Learn Hadoop Training from the Industry Experts we bridge the gap between the need of the industry. Bangalore Training Academy provide the Best Hadoop Training in Bangalore with 100% Placement Assistance. Book a Free Demo Today.
Big Data Analytics Training in Bangalore
Tableau Training in Bangalore
Data Science Training in Bangalore
Workday Training in Bangalore

merlin said...

Thanks for sharing such an informative blog.Awaiting for your next update.

Selenium Training in chennai | Selenium Training in annanagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery

subha said...

Thanks for sharing such an informative blog.Awaiting for your next update. i really enoy to read.
C and C++ Training Institute in chennai | C and C++ Training Institute in anna nagar | C and C++ Training Institute in omr | C and C++ Training Institute in porur | C and C++ Training Institute in tambaram | C and C++ Training Institute in velachery

un known said...

blog commenting : Thanks for sharing this information. I really Like Very Much.
angular js online training

radhika said...

Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge as updated one, keep blogging.

AWS training in Chennai

AWS Online Training in Chennai

AWS training in Bangalore

AWS training in Hyderabad

AWS training in Coimbatore

AWS training



svrtechnologies said...


I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.I want to share about Mulesoft training in hyderabad .

svrtechnologies said...


I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.I want to share about tibco training .

Unknown said...

Thanks for one marvelous posting!
Java Training in Bangalore

Java Training

Java Training in Hyderabad

Java Training in Chennai

Java Training in Coimbatore

Anonymous said...

Like your posting!Thankyou for sharing ..
Android Training in Bangalore

Android Training

Android Online Training

Android Training in Hyderabad

Android Training in Chennai

Android Training in Coimbatore

veera said...

Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website | Certification | Cyber Security Online Training Course|

Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course|

CCNA Training Course in Chennai | Certification | CCNA Online Training Course|

RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai|

SEO Training in Chennai | Certification | SEO Online Training Course

ramya devi said...

Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my websiteDevOps Training in Bangalore

DevOps Training

DevOps Online Training


DevOps Training in Hyderabad

DevOps Online Training in Chennai

DevOps Training in Coimbatore

jdgvks said...

thanks for your information really good and very nice
hadoop training in bangalore

oracle training in bangalore

hadoop training in acte.in/oracle-certification-training">oracle training

oracle online training

oracle training in hyderabad

hadoop training in chennai

Unknown said...

Nice info. Thanks for sharing info about about c language training. I want to learn c training this tutorial is really helpful. Thanks a lot. Keep updating tutorials……
Data Science Training In Bangalore

Data Science Training

Data Science Online Training

Data Science Training In Hyderabad

Data Science Training In Chennai

Data Science Training In Coimbatore

sahasrit said...

Nive and informative article. amazon web services aws training in chennai

microsoft azure training in chennai

workday training in chennai

android-training-in chennai

ios training in chennai

Anonymous said...

nice article
thanks for sharing
data science course in chennai

ccna course in chennai

iot course in chennai

ethical hacking course in chennai

cyber security course in chennai

Veera Blogspot said...

Too good article,Keep sharing more article posts with us.

Thank you...

Best ServiceNow Online Training

Unknown said...

Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
blockchain online training
best blockchain online training
top blockchain online training

Jon Hendo said...

tools that automate and scale events personalize attendee experiences and deliver positive ROI. event marketing, thank you emails and volunteer thank you letter template

KITS Technologies said...

Say, you got a nice article post.Really thank you! Really Great.
salesforce training
hadoop training
mulesoft training
linux training
etl testing training

Kaparthicynixit said...

Thank You for Sharing this wonderful and much required information in this post.
Visit us: Dot Net Training Online India
Visit us: .Net Online Training Hyderabad

bhanu said...

Thanks for Sharing This Article.It is very so much valuable content.
Pega Training Hyderabad
Pega Online Training

Sarika A said...

Thanks for sharing this great information I am impressed by the information that you have on this blog. We are also providing the best services click on below links to visit our website.
Oracle Fusion HCM Training
Workday Training
Okta Training
Palo Alto Training
Adobe Analytics Training

Mrbk30 said...

Very Informative blog thank you for sharing. Keep sharing.

Best software training institute in Chennai. Make your career development the best by learning software courses.

azure training in chennai
devops training in chennai
power bi training in chennai

Block said...

It has been simply incredibly generous with you to provide openly
what exactly many individuals would’ve marketed for an eBook to end
up making some cash for their end, primarily given that you could
have tried it in the event you wanted.
ASP Dot Net Training in Chennai
C Sharp Training in Chennai
big data hadoop training in chennai

Block said...

It has been simply incredibly generous with you to provide openly
what exactly many individuals would’ve marketed for an eBook to end
up making some cash for their end, primarily given that you could
have tried it in the event you wanted.
mysql training in chennai
unix training in chennai
Software training institute in chennai

Anonymous said...

mmorpg oyunlar
instagram takipçi satın al
TİKTOK JETON HİLESİ
tiktok jeton hilesi
Sac ekimi antalya
referans kimliği nedir
İnstagram Takipçi Satın Al
Metin2 Pvp Serverlar
İNSTAGRAM TAKİPÇİ

PrasannaNareshIT said...

Hi,
Thanks for sharing such a great information. spoken english online training - NareshIT

Post a Comment