Saturday, 14 December 2013
Saturday, December 14, 2013
C Programming Tutorial
Friday, 13 December 2013
Friday, December 13, 2013
Part:1:-C Programming
Part-1 C Programming-Introduction
Before going
to Start C Programming, Take a Look at Few Definitions:-
What is Program:-
A Program
(i.e. Computer Program) is a Sequence of instructions, written to perform a
Specified task with Computer.
Task of developing
programs is called Programming.
Who is Programmer:-
The Person
who is engaged in Programming Activity is known as Programmer. We can also say
that Programmer is a person who writes Computer Software.
Introduction to
C-Programming language
C is a
general-purpose programming language developed by Dennis Ritchie for the Unix Operating System in 1972 at Bell Laboratories. C is successor of B language which
was introduced around 1970. C is also Known as Middle level Language because it
combines the best elements of low level or Machine language with high level
language.
C Language
has the ability to communicate directly with hardware makes it powerful Choice
for System Programmers for writing system programs like Compiler and
Interpreters. Today C is most widely used System Programming language. UNIX and
Linux Operating System are written using C Language.
Why you should Learn C?
C is simple and Easy to Learn.
C is structured programming language.
C can compiled on variety of computers and programs written
in C runs faster as Compared to other programming language.
C Compiler:-
C programs
are written into text files with extension “.c”. Example helloworld.c.
After creating a program using C language, if you want to run your program then
you need a compiler. Compiler converts your program into a language
understandable by a computer i.e. Machine
language (binary format).If you don’t have Compiler than you have to download
it. Without Compiler you are not able to run your C Program.
Compiler
vendors provides several Integrated Development Environment (IDE) which contain
Editor as well as Compiler. There are several IDE available in the market
targeting different Operating System. For Example:-Turbo C++, Borland C++,
Microsoft C++ etc.
Example1.1: A Simple C Program:-
#include <stdio.h>
#include <conio.h>
void main()
{
printf("Hello
World");
getch();
}
Explanation of Program:
#include is
directive to C preprocessor known as Compiler Directive. Lines starting with #
are processed by the preprocessor before the program is compiled by the
Compiler. As we know that C is Small Language and it can do almost nothing
without including the External Libraries. So, we have to tell the compiler what
external code we want to use by including header files. In above example we
have used two header files i.e. “stdio.h” and “conio.h”. The stdio library (standard
input/output header) contains the code that allow us to read and write data
from and to the terminal (Console).
Every
program starts Executing from the main function. C Program can contain one or
more function out of which one must be main. When printf statement executed, It
prints Hello World message to the terminal.
Note:-
C is a Case sensitive Language.
Always terminate the statement using semi-colon.
Example 1.2 Using Escape Sequence:-
#include <stdio.h>
#include <conio.h>
void main()
{
printf("Hello
World\n");
printf("Welcome
to C Programming Introduction");
getch();
}
When printf
statement executed, all the characters inside double quotes printed exactly
same as the written in the code till it encounter the backslash. On
encountering the backslash (“\”) in the string, it combines backslash with the
next character and form an Escape
Sequence. In Example 1.2 it form “\n” which means new line. When “\n”
comes, the cursor moves to the next line and starts writing the characters from
next line.
Escape Sequence
|
Description
|
\n
|
New Line
|
\a
|
Alert Sound
|
\t
|
Horizontal tab
|
\”
|
Inserting Double quote in string
|
\\
|
Inserting backslash
in string
|
Table 1.1 Escape Sequence
Comments: Comments help people to read and
understand your Program code. Comments are ignored by the Compiler. We can use
Comments in two ways:-
Single line
Comment:-
//This is the Example of Single Line
Comment
Multiline
Comment:-
/* this is the example of Multiline
Comment
Program Created by Anoop Kumar
Sharma*/