Vous êtes sur la page 1sur 2365

ScribdExplore

Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.



C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.



Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf
willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.



It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970



The language was formalized in 1988 by the American National StandardInstitute
(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.



White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.



It can be compiled on a variety of computers.
Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions



Comments The following program is written in the C programming language. Open a
text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.



Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.
C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.



C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.



Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf
willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.



It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970



The language was formalized in 1988 by the American National StandardInstitute
(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.



White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.



It can be compiled on a variety of computers.
Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions



Comments The following program is written in the C programming language. Open a
text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.



Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.
C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.



C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.



Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf
willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.



It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970



The language was formalized in 1988 by the American National StandardInstitute
(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.



White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.



It can be compiled on a variety of computers.
Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions



Comments The following program is written in the C programming language. Open a
text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.



Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.
C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.



C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.



Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf
willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.



It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970



The language was formalized in 1988 by the American National StandardInstitute
(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.



White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.



It can be compiled on a variety of computers.
Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions



Comments The following program is written in the C programming language. Open a
text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.



Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.
C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.



C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information


Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.



Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4
double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf
willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.



It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970



The language was formalized in 1988 by the American National StandardInstitute
(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved
C Programming Tutorials Doc
Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127
unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.
#include <stdio.h>int main()
{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".
Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255


float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.
C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}
You're reading a preview. Unlock full access with a free trial.
Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8
long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.
C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12
These figures only apply to today's generation of PCs. Mainframes and
midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial
Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.



White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.



It can be compiled on a variety of computers.
Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample
Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.
Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.
{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.
$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document
3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview


Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48

Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful
ScribdExplore
Search
Search
No search results.
UploadSaved

C Programming Tutorials Doc


Uploaded by Sumit Gupta on Oct 04, 2011
Related Interests
C (Programming Language)Control FlowPointer (Computer Programming)SubroutineData
Type
Rating and Stats
0
0
441 views
Document Actions
Download
Save for Later
Other Actions
SHARE OR EMBED DOCUMENT
Embed
View More
Copyright: Attribution Non-Commercial (BY-NC)
List price: $0.00
Download as PDF, TXT or read online from Scribd
Flag for inappropriate content
Recommended Documents
Documents Similar To C Programming Tutorials Doc
document
Notes of c Language
by api-3723265
document
Programming in C
by api-3707023
document
C Programming Notes
by Swetabh Tiwary
Documents About C (Programming Language)
document
Manhattan Associates Programming Placement Paper Level1
by placementpapersample
document
CryptoWall Report
by CoinDesk
document
OOP (Java & VB) MCQ'S
by GuruKPO
Documents About Pointer (Computer Programming)
document
Mindfire Solutions Sample Programming Placement Paper Level1
by placementpapersample
document
KPIT Sample Programming Placement Paper Level1
by placementpapersample
document
Geometric_Sample_Programming_Placement_Paper_Level1
by placementpapersample

Search document

3
You are on page 3of 48
Screen Reader Compatibility Information

Due to the method this document is displayed on the page, screen readers may not
read the content correctly. For a better experience, please download the original
document and view it in the native application on your computer.

C Programming Tutorials
Basic Introduction
C is a general-purpose high level language that was originally developed by
DennisRitchie for the Unix operating system. It was first implemented on the
DigitalEquipment Corporation PDP-11 computer in 1972. The Unix operating system and
virtually all Unix applications are written in the Clanguage. C has now become a
widely used professional language for various reasons.

Easy to learn

Structured language

It produces efficient programs.

It can handle low-level activities.

It can be compiled on a variety of computers.


Facts about C

C was invented to write an operating system called UNIX.

C is a successor of B language which was introduced around 1970

The language was formalized in 1988 by the American National StandardInstitute


(ANSI).

By 1973 UNIX OS almost totally written in C.

Today C is the most widely used System Programming Language.

Most of the state of the art software have been implemented using C
Why to use C ?
C was initially used for system development work, in particular the programs
thatmake-up the operating system. C was adopted as a system development
languagebecause it produces code that runs nearly as fast as code written in
assembly language.Some examples of the use of C might be:

Operating Systems

Language Compilers

Assemblers

Text Editors

Print Spoolers

Network Drivers

Modern Programs

Data Bases

Language Interpreters

Utilities
C Program File
All the C programs are written into text files with extension ".c" for example
hello.c. Youcan use "vi" editor to write your C program into a file. This tutorial
assumes that you know how to edit a text file and how to writeprogramming
instructions inside a program file.

C Compilers
When you write any program in C language then to run that program you need
tocompile that program using a C Compiler which converts your program into a
languageunderstandable by a computer. This is called machine language (ie. binary
format). Sobefore proceeding, make sure you have C Compiler available at your
computer. It comesalong with all flavors of Unix and Linux.If you are working over
Unix or Linux then you can type gcc -v or cc -v and check theresult. You can ask
your system administrator or you can take help from anyone toidentify an available
C Compiler at your computer.If you don't have C compiler installed at your computer
then you can use below givenlink to download a GNU C Compiler and use it.
Program Structure
A C program basically has the following form:

Preprocessor Commands

Functions

Variables

Statements & Expressions

Comments The following program is written in the C programming language. Open a


text file hello.cusing vi editor and put the following lines inside that file.

#include <stdio.h>int main()


{
/* My first program */printf("Hello, TechPreparation! \n");return 0;
}
Preprocessor Commands:
These commands tells the compiler to do preprocessing before doing actual
compilation.Like #include <stdio.h> is a preprocessor command which tells a C
compiler to includestdio.h file before going to actual compilation. You will learn
more about CPreprocessors in C Preprocessors session.
Functions:
Functions are main building blocks of any C Program. Every C Program will have one
ormore functions and there is one mandatory function which is called main()
function. This function is prefixed with keyword int which means this function
returns an integervalue when it exits. This integer value is returned using return
statement. The C Programming language provides a set of built-in functions. In the
above exampleprintf() is a C built-in function which is used to print anything on
the screen.

Variables:
Variables are used to hold numbers, strings and complex data for manipulation. You
will learn in detail about variables in C Variable Types.
Statements & Expressions :
Expressions combine variables and constants to create new values. Statements
areexpressions, assignments, function calls, or control flow statements which make
up Cprograms.
Comments:
Comments are used to give additional useful information inside a C Program. All
thecomments will be put inside /*...*/ as given in the example above. A comment can
spanthrough multiple lines.
Note the followings

C is a case sensitive programming language. It means in C printf and Printf


willhave different meanings.

C has a free-form line structure. End of each C statement must be marked witha
semicolon.

Multiple statements can be one the same line.

White Spaces (ie tab space and space bar ) are ignored.

Statements can continue over multiple lines.


C Program Compilation
To compile a C program you would have to Compiler name and program files
name.Assuming your compiler's name is cc and program file name is hello.c, give
followingcommand at Unix prompt.

$cc hello.c This will produce a binary file called a.out and an object file hello.o
in your currentdirectory. Here a.out is your first program which you will run at
Unix prompt like anyother system program. If you don't like the name a.out then you
can produce a binaryfile with your own name by using -o option while compiling C
program. See an examplebelow$cc -o hello hello.cNow you will get a binary with name
hello. Execute this program at Unix prompt butbefore executing / running this
program make sure that it has execute permission set.If you don't know what is
execute permission then just follow these two steps$chmod 755 hello$./hello This
will produce following resultHello, TechPreparation!Congratulations!! you have
written your first program in "C". Now believe me its notdifficult to learn "C".

Basic Datatypes
C has a concept of 'data types' which are used to define a variable before its use.
Thedefinition of a variable will assign storage for the variable and define the
type of datathat will be held in the location. The value of a variable can be
changed any time.C has the following basic built-in datatypes.

int

float

double

charPlease note that there is not a Boolean data type. C does not have the
traditional viewabout logical comparison, but that's another story.
int - data type
int is used to define integer numbers.

{ int Count;Count = 5;
}
float - data type
float is used to define floating point numbers.{ float Miles;Miles = 5.6;
}
double - data type
double is used to define BIG floating point numbers. It reserves twice the storage
for thenumber. On PCs this is likely to be 8 bytes.{ double Atoms;Atoms = 2500000;
}
char - data type
char defines characters.{ char Letter;Letter = 'x';
}

You're reading a preview. Unlock full access with a free trial.


Pages 5 to 48 are not shown in this preview.
Download With Free Trial

Modifiers
The data types explained above have the following modifiers.

short

long

signed

unsigned The modifiers define the amount of storage allocated to the variable. The
amount of storage allocated is not cast in stone. ANSI has the following
rules:short int <= int <= long intfloat <= double <= long doubleWhat this means is
that a 'short int' should assign less than or the same amount of storage as an
'int' and the 'int' should be less or the same bytes than a 'long int'. Whatthis
means in the real world is:
Type Bytes Range
short int2 -32,768 -> +32,767(32kb)unsigned short int20 -> +65,535(64Kb)unsigned
int40 -> +4,294,967,295( 4Gb)int4-2,147,483,648 -> +2,147,483,647( 2Gb)long int 4-
2,147,483,648 -> +2,147,483,647( 2Gb)signed char1-128 -> +127

unsigned char10 -> +255

float4

double8

long double12

These figures only apply to today's generation of PCs. Mainframes and


midrangemachines could use different figures, but would still comply with the rule
above.You can find out how much storage is allocated to a data type by using the
sizeof operator discussed in Operator Types Session.Here is an example to check
size of memory taken by various datatypes.intmain()
{
printf("sizeof(char) == %d\n", sizeof(char));printf("sizeof(short) == %d\n",
sizeof(short));printf("sizeof(int) == %d\n", sizeof(int));printf("sizeof(long) ==
%d\n", sizeof(long));printf("sizeof(float) == %d\n",
sizeof(float));printf("sizeof(double) == %d\n", sizeof(double));printf("sizeof(long
double) == %d\n", sizeof(long double));printf("sizeof(long long) == %d\n",
sizeof(long long));

You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview
Unlock full access with a free trial.
Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
You're Reading a Preview

Unlock full access with a free trial.


Download With Free Trial
Recommended Documents
Documents Similar To C Programming Tutorials Doc

document
Notes of c Language
document
Programming in C
document
C Programming Notes
document
C Programming
document
C Language Full Notes
document
simple c programs
document
Important C Programs
document
c programming
document
Programming in C by Kute T. B.
document
C-programs
document
wipro
document
C Programs
document
C-Notes for Student
document
complete c programming notes according to syllbus
document
c programming using pointers
document
C++ Notes Complete
document
C Program examples, program list
document
100 C Programming Exercises
document
C Language Super Notes 2
document
Sample C Programs
document
C Sample Programs
document
Lecture 16
document
Some Important programs on Strings(in C)
document
C Programming Lecture Notes 2008-09
document
C Lecture Notes
document
C and Data Structure notes
document
C++ Notes
document
C++ Programs Collection
document
C Language Notes
document
Oops Notes(c++) by:yatendra kashyap
carousel next
Documents About C (Programming Language)

document
Manhattan Associates Programming Placement Paper Level1
document
CryptoWall Report
document
OOP (Java & VB) MCQ'S
document
ERP System MCQ'S
document
Thompson_Reuters__Sample_Technical_Placement_Paper_Level1
document
Artificial Intelligence MCQ'S
document
johnson_19880908.pdf
document
Analysis & Design Algorithm MCQ'S
document
SYSTEM ANALYSIS AND DESIGN
document
OOSE MCQ'S
document
Marco Arment 2006 resume
document
Simulation and Modeling MCQ'S
document
Delphi Sample Programmming Placement Paper Level1
document
System Analysis and Design
document
h2_19810502.pdf
document
Sonata Software Sample Programming Placement Paper Level1
document
frsbog_mim_v29_0030.pdf
document
Object Oriented Programming 2011
document
CA Technologies Sample Programming Placement Paper Level1
document
11459_1985-1989
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
null
document
Mindtree Sample Programming Placement Paper Level-I
document
Texas Instruments Sample Programming Placement Paper Level1
document
Operating System Fundamentals
document
Tcs Programming Placement Paper
document
System Analysis and Design MCQ'S
document
CGI Sample Programming Placement Paper Level1
document
As NZS 5050-2010 Business Continuity - Managing Disruption-related Risk
document
Lehman Brothers Sample technical Placement Paper Level1
carousel next
Documents About Pointer (Computer Programming)

document
Mindfire Solutions Sample Programming Placement Paper Level1
document
KPIT Sample Programming Placement Paper Level1
document
Geometric_Sample_Programming_Placement_Paper_Level1
document
Idea Cellular Sample Programming Placement Paper Level1
document
ThoughtWorks Sample Programming Placement Paper Level1
document
Sasken_Sample_Programming_Placement_Paper_Level1
document
VeriFone_Sample_Programming_Placement_Paper_Level1
document
tmpBF89
document
Ebay Inc Sample Programming Placement Paper Level1
document
NIIT Sample Programming Placement Paper Level-1
document
Principal of Programming Language
document
Oracle Financial Services Software Sample Programming Placement Paper Level1
document
As NZS 1486-1993 Information Technology - Programming Languages - Fortran 90
document
GAIL (India) Ltd. Sample Programming Placement Paper Level1
document
Firstsource Sample Programming Placement Paper Level1
document
Epicsystems Inc Sample Programming Placement Paper Level1
document
iNautix Technologies programming Placement Paper Level1
carousel next
Footer Menu
ABOUT
About Scribd
Press
Our blog
Join our team!
Contact Us
Invite Friends
Gifts
LEGAL
Terms
Privacy
Copyright
SUPPORT
Help / FAQ
Accessibility
Purchase help
AdChoices
Publishers
Social Media
Scribd - Download on the App StoreScribd - Get it on Google Play
Copyright 2017 Scribd Inc. .Browse Books.Mobile Site.Site Directory.Site
Language:
English
This document is...
UsefulNot useful

Vous aimerez peut-être aussi