0% found this document useful (0 votes)
4 views

Introduction to c

The document provides an overview of the C programming language, including its history, features, and key concepts such as data types, variables, and tokens. It highlights the development of C by Dennis Ritchie in 1972 and outlines the structure of C programs. Additionally, it covers essential elements like character sets, keywords, and user-defined data types.

Uploaded by

Sahitya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Introduction to c

The document provides an overview of the C programming language, including its history, features, and key concepts such as data types, variables, and tokens. It highlights the development of C by Dennis Ritchie in 1972 and outlines the structure of C programs. Additionally, it covers essential elements like character sets, keywords, and user-defined data types.

Uploaded by

Sahitya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Programming with

C Language

Shri Vishnu Engineering College for Women ::


1
Information Technology
Program Development Steps- Revised

Shri Vishnu Engineering College for Women ::


2
Information Technology
Introduction to C Language

• C is a general-purpose, middle level, structured


computer programming language.

• C was originally developed under UNIX


environment. C was initially used for system
development work, in particular the programs that
make up the operating system.

• C stands for Combined Programming Language and


sometimes called System Programming Language
Shri Vishnu Engineering College for Women ::
3
Information Technology
History and Evaluation of C Language
C Language was developed by Dennis Ritchie in
the year of 1972.

CPL – Common Programming Language invented


by Martin Richards in 1960’s
BCPL – Basic Combined Programming Language Ken Thompson
by Martin Richards in 1966
B Language – by Ken Thompson & Dennis Ritchie
in 1969
Traditional C – by Dennis Ritchie in 1972
K&R C – by Kernighan & Dennis Ritchie in 1978
ANSI C – by ANSI Committee in 1989 Dennis Ritchie
ANSI/ISO C – by ISO Committee in 1990
C99 – by Standardization Committee in 1999
Shri Vishnu Engineering College for Women ::
4
Information Technology
Features of C Language

Shri Vishnu Engineering College for Women ::


5
Information Technology
Key aspects of C Language

• Character Sets
• Keywords
• Identifiers
• Datatypes
• Operators
• Decision Making Statements
• Looping Statements
• Functional Programming
• Dealing with Multi-Valued Variables- Arrays
• User defined data types- structures and unions

Shri Vishnu Engineering College for Women ::


6
Information Technology
Example Program

#include <stdio.h>
main()
{
printf("hello world \n Welcome to C Language");
return 0;
}

Shri Vishnu Engineering College for Women ::


7
Information Technology
C Character Sets

• C language consist of some characters set, numbers and


some special symbols.
• The character set of C consist of all the alphabets of
English language.
• Alphabets: a to z, A to Z
• Numeric digits: 0,1 to 9
• Special Symbols :{ , } , [ , ] , ( , ), ?, +, - ,*, / , % , ! , ; ,
& , |, # , : , “ , ‘, \, < , >

Shri Vishnu Engineering College for Women ::


8
Information Technology
Tokens in C Language

• The words formed from the character set


are building blocks of C and are sometimes
known as tokens.
• These tokens represent the individual entity
of language.
1) Identifiers 2)Keywords
3)Constants 4) Operators
5)Variables 6) Escape Sequence
Characters

Shri Vishnu Engineering College for Women ::


9
Information Technology
Identifiers

• An identifier is a word used by a


programmer to name a variable , function,
or label.
• Rules for identifiers in C:
– first char alphabetic [a-z,A-Z] or underscore (_)
– has only alphabetic, digit, underscore chars
– Maximum length of variable is 32
– cannot use keywords as variables
– case (upper/lower) matters
Shri Vishnu Engineering College for Women ::
10
Information Technology
Keywords

• Keywords are nothing but auto double int struct


system defined identifiers.
break else long switch
• Keywords are reserved
words of the language. case enum register typedef

• They have specific char extern return union


meaning in the language
and cannot be used by the const float short unsigned
programmer as variable or
constant names continue for signed void

• There are 32 Keywords in default goto sizeof volatile


C Programming
do if static while

Shri Vishnu Engineering College for Women ::


11
Information Technology
Variables
• A variable is nothing but a name given to a storage area
• Each variable in C has a specific type, which determines the
size and layout of the variable's memory; the range of values
that can be stored within that memory; and the set of
operations that can be applied to the variable.
• Rules for declaring a variable
• has only alphabetic, digit, underscore chars
• First char alphabetic [a-z,A-Z] or underscore (_)
• Maximum length of variable is 32
• cannot use keywords as variables
• case (upper/lower) matters.
• Syntax of declaring a variable in program
• <datatype> <variable name>
Shri Vishnu Engineering College for Women ::
12
Information Technology
Variables

• age
• _age

• Age*

• Ag_e

• 4age
• ag4e
• int
• intage
Shri Vishnu Engineering College for Women ::
13
Information Technology
Escape Sequence Characters
• Sometimes, it is necessary to use characters which cannot be
typed or has special meaning in C programming.
• For example: \n is used for newline. The backslash ( \ ) causes
"escape" from the normal way the characters are interpreted
by the compiler.
• \n Newline
• \b Backspace
• \f Form feed
• \r Return
• \t Horizontal tab
• \\ Backslash
• \' Single quotation mark
• \" Double quotation mark
• \? Question mark
• \0 Null character

Shri Vishnu Engineering College for Women ::


14
Information Technology
Datatypes
• C has a concept of 'data types' which are used to define a
variable before its use.
• The definition of a variable will assign storage for the variable
and define the type of data that will be held in the location.
• This determines the type and size and range of data associated
with variables.
• Usage of datatype associated with variable in program
• datatype variable_name
• Categories of Datatypes
• Primary Datatypes
• Derived Datatypes
• User defined datatypes

Shri Vishnu Engineering College for Women ::


15
Information Technology
Primary Datatypes
• These are fundamental data types in C to represent
various different kinds of values in programs
Datatype Purpose
int Used to denote all numeric
values without decimal point
float Used to denote all numeric
values with decimal point and
precision of 6 digits
double Used to denote all numeric
values with decimal point and
precision of 10 digits
char Used to denote all character
values.

Shri Vishnu Engineering College for Women ::


16
Information Technology
int Datatype
• Integer data type allows a variable to store numeric
values.
• “int” keyword is used to refer integer data type.
• The storage size of int data type is 2 bytes.
• int (2 byte) can store values from -32,768 to +32,767
Ex:
int x;
int radius;
int student_age;
int Marks_Subject_1;
Shri Vishnu Engineering College for Women ::
17
Information Technology
float Datatype
• Float data type allows a variable to store decimal values.
• Storage size of float data type is 4 Bytes.
• We can use up-to 6 digits after decimal using float data type.
• Keyword for floating point datatype is “float”
• Range of float is 3.4E-38 to 3.4E+38 or
3.4* 10-38 to 3.4* 1038

• For example, 10.456789 can be stored in a variable using


float data type.
Ex:
float average;
float percentage;
float Circle_area;
Shri Vishnu Engineering College for Women ::
18
Information Technology
double Datatype
• Double data type allows a variable to store decimal values.
• Storage size of double data type is 6.
• We can use up-to 10 digits after decimal using double data
type.
• Keyword for double point datatype is “double”
• Range of double is 1.7E-308 to 1.7E+308 or
1.7* 10-308 to 1.7* 10308
• For example, 10.6789236456 can be stored in a variable
using double data type.
• Ex:
double range;
double max_value;
Shri Vishnu Engineering College for Women ::
19
Information Technology
char Datatype
• Character data type allows a variable to store only one
character.
• Storage size of character data type is 1. We can store only one
character using character data type.
• “char” keyword is used to refer character data type.
• Range of char datatype is -128 to 128
• For example, ‘A’ can be stored using char datatype. You can’t
store more than one character using char data type.
Ex:
char name;
char gender;

Shri Vishnu Engineering College for Women ::


20
Information Technology
Modifiers in Datatype
• The amount of memory space to be allocated for a variable is
derived by modifiers.
• Modifiers are prefixed with basic data types to modify (either
increase or decrease) the amount of storage space allocated to
a variable.
• For example, storage space for int data type is 4 byte for 32 bit
processor. We can increase the range by using long int which is 8
byte. We can decrease the range by using short int which is 2 byte.
• There are 5 modifiers available in C language. They are,
• short
• long
• signed
• unsigned
• long long

Shri Vishnu Engineering College for Women ::


21
Information Technology
Size and Range of Datatypes

Shri Vishnu Engineering College for Women ::


22
Information Technology
Derived Datatype
• A derived type is formed by using one or more basic
types in combination.
• Using derived types, an variety of new types can be
formed like arrays, pointers.

Shri Vishnu Engineering College for Women ::


23
Information Technology
User defined Datatype
• Those data types which are defined by the user as per
requirement are called user-defined data types.
• Examples of such data types are structure, union and
enumeration.

Shri Vishnu Engineering College for Women ::


24
Information Technology
Classification of Datatypes

Shri Vishnu Engineering College for Women ::


25
Information Technology

You might also like