SlideShare a Scribd company logo
1 of 25
1.1 History of C Language
Language Name Year of development Description
ALGOL 60 1960 TOO ABSTRACT AND TOO SHORT
CPL 1963 COMBINED P.L
BCPL 1967 USED TO WRITE SYSTEM S/W.
WAS NOT SO POWERFUL.
B 1970 MACHINE DEPENDENT
C 1972 GENERAL PURPOSE,COMPILED,
STRUCTURED P.L, WITH UNIX O.S
- ‘C’ LANGUAGE WAS DEVELOPED BY ‘DENNIS RITCHIE’ AT AT &T BELL LABORATORY IN 1972.
Vijayalaxmi D Wakode
Importance of C
1. It is robust language whose rich set of built in functions and operators
can be used to write any complex program.
2. The language is very well suited from writing both system s/w and
business package. We can also write compilers .
3. We can also write structural programs using C language.
Character Set of C
LETTERS A-Z, a-z
DIGITS 0-9
SPECIAL CHARACTER _ ,! , etc.
WHITE SPACES tab , enter , etc.
The white spaces are ignored by compiler unless they are part of strings.
Vijayalaxmi D Wakode
1.2 TOKENS IN C
• To form a program i.e. set of executable statement , we need grammar.
Like all language , C language also has its own rules and grammar known
as syntactic rules / syntax.
• The smallest individual unit in a program is known as ‘Token’.
e.g. int,
char, float,
do , etc
Num , hello,
world, etc
e.g.
10,5, 90.11,
etc
e.g.
+ , - , * , %,/,
etc
e.g. “Hello
This is 1st
lecture”
e.g.
{},[], etc
Vijayalaxmi D Wakode
i) Keywords
• A keyword is a reserved word whose meaning can’t be changed by user.
• Keyword serves as a basic building block for program design and
development. The keywords must be written in ‘Lower Case’ , they have
predefined meaning .
• The C language consists of 32 keywords.
Table 1.1 Keywords in ANSI C Vijayalaxmi D Wakode
ii)Identifier
• The words other than the keywords that are used in C program are
known as ‘Identifiers’. These are the names that can be given to
various program elements as variable, function, etc.
• Identifier is user defined name.
• The language identifies only 1st 32 characters as the identifiers.
Naming rules for identifier
a) First letter of identifier should not start with a digit
b) Upper case and lower case letters are different
c) The keyword name can’t be identifier
d) White spaces and special symbols except underscore( _ ) are not allowed
Vijayalaxmi D Wakode
iii) Constants
• In C language , the constants are referred to fixed values that don’t change
during program execution.
Figure 1.1: Types of constants in C Vijayalaxmi D Wakode
a)Integer Constants
• Decimal Integers : consists of a set of digits 0 to 9 preceded by an optional + or –
sign. Spaces, commas and non digit characters are not permitted between digits.
e.g. 12, -44 , 787878
• Octal Integers : consists of any combination of digits from 0 to 7 with prefix O.
e.g. O26, O22 , O7
• Hexadecimal Integers : it is preceded by OX or Ox, they may contain alphabets
from A to F(10-15) or a to f(10-15)
• The quantities that are represented by numbers containing fractional parts are
called real or floating point constants. These quantities are represented by
numbers containing fractional parts like 98.72.
e.g. 0.0023, -9.8
b)Real Constants
Vijayalaxmi D Wakode
c) single character constants
• These constants are of a single character may be an alphabet, digit or special
symbol that is enclosed in a pairs of single quotation marks .
e.g. ‘x’ , ‘12’ , ‘ . ’ , etc.
• These consists of the sequence of characters that are enclosed within a pairs of a
double quotation marks.
e.g. “Introduction of C” , “XYZ 123 ” , etc.
• In C , every string is terminated by ‘0’ . It is null character that is automatically
added to the string by the compiler . It is backslash character constant. These are
also known as escape sequence character .
d) string character constants
Vijayalaxmi D Wakode
Escape sequence characters
• Backslash used in front of these characters tells the compiler to
escape from regular behavior and perform the desired function.
• List of the other such characters is as shown
n new line
b backspace
t horizontal space
o null character
r carriage return
• The constants can be defined in 2 ways in program.
-we can give a direct value that is used as constant. E.g. int a=10.
-we can use #define preprocessor directive. E.g. #define PI 3.14
Vijayalaxmi D Wakode
iv)Operator
• A operator is defined as a symbol that tells the computer to perform
certain mathematical or logical manipulation.
• These are basically used to manipulate data .
• C provides a rich set of built in operators.
Vijayalaxmi D Wakode
a) Arithmetic Operator
• The C language supports various different arithmetic operators as +,-,/,*,%.
The % is known as modulus operator used to find remainder of an expression.
Integer Arithmetic
• An arithmetic operation performed on 2 whole numbers/ integers . It always
gives an integer result. In integer division the fractional part is truncated.
Floating point Arithmetic
• An arithmetic operation performed on 2 real / fractional numbers. It results
can be truncated according to the properties requirement. The remainder
operator (%) is not applicable for floating point arithmetic operands.
Mixed mode Arithmetic
• An arithmetic operation performed on 1 of real operands and another integer
operand. Its result is always real.
Vijayalaxmi D Wakode
b)Comparison Operator
• These operators are also known as relational operator. These are used to
compare 2 quantities. The value of relational expression is either 0/1. If
expression is true then 1 and 0 if its false
• Syntax : exp1 relational operator exp2. e.g. -90 > 0 false(0), 11> 7+2 true(1)
• Relational operator are used in decision making statements in C language.
symbols meaning
< Less than
<= Less than equal to
> Greater than
>= Greater than equal to
== Equal to
!= Not equal to
Vijayalaxmi D Wakode
c) Logical Operator
• The language supports 3 kinds of logical operator. These are basically used
when we want to use more than 1 condition and make certain decision.
i)Logical AND (&&) ii)Logical OR(||)
iii) Logical NOT(!)
A B o/p : A && B
0 0 0
0 1 0
1 0 0
1 1 1
A B o/p : A|| B
0 0 0
0 1 1
1 0 1
1 1 1
A o/p: !A
0 1
1 0
Vijayalaxmi D Wakode
v) Assignment Operator
• These are used to assign the result of an expression to a variable / it
can also be used to assign value to a variable.
• In case of assignment operator L.H.S must be a variable but R.H.S can
be expression or any constant value.
e.g. A = 2, x = A + 3
• C language also supports set of short hand assignment operator .
Operator Stmt with simple assign
operator
Stmt with shorthand
property
+= a=a+1 a+=1
-= a=a-1 a-=1
*= a=a*1 a*=1
/= a=a/1 a/=1
%= a=a%1 a%=1
Vijayalaxmi D Wakode
v) Unary Operator
Vijayalaxmi D Wakode
vi)Conditional Operator
• Conditional operator operates 3 conditions, hence also known as
ternary operator.
Syntax : expr1 ? expr2 : expr3;
e.g. (5>10)? printf(“5”); : printf(“10”);
• Expr1 is evaluated first. Its value is either true or false . If it is true the
expr2 is evaluated and this becomes value of complete expr. If expr1
is false, then expr3 is evaluated and this becomes the value of
complete expr. Only 1 of the expr’s i.e expr2/ expr3 will be evaluated
but not both.
• Conditional operator is short form of if…else structure.
Vijayalaxmi D Wakode
vii)Bitwise Operator
• C language also supports various bitwise operator that operates at bit level.
These are used to test bits them in left / right.
• The o/p of bitwise AND is 1 if all the corresponding bits of all operands is 1.
• The o/p of bitwise OR is 1 if at least one corresponding bits of all operands is 1.
• The o/p of bitwise XOR is 1 if the corresponding bits of 2 operands are opposite.
• Bitwise complement operator is an unary operator. It changes 1 to 0(condition).
operator meaning
& Bitwise and
| Bitwise or
~ Complement
^ Bitwise exclusive or
<< Shift left
>> Shift right
Vijayalaxmi D Wakode
viii) Special Operator
• C language also supports some special operators as comma, sizeof(),
pointer operator (*), member selection operator( . )
i) comma operator :
It is used to separate variables.
e.g. int a,b,c;
ii) sizeof operator :
The sizeof is a compile time operator that returns the numbers of
bytes the operand occupies. The operand may be a variable , constant or
datatype qualifier.
e.g. int x,y;
y=sizeof(x);
o/p: y = 2 Vijayalaxmi D Wakode
1.3 Data Types in C
• Datatype means type of data which we are going to give to computer for
processing. It basically used to calculate the memory requirement.
fig. 1.2. Data types in C
Vijayalaxmi D Wakode
Primary Data Types
These are the built in and fundamental data types .
Integers are whole numbers i.e. numbers without decimal point. All these data types
short int, int, long int have signed & unsigned forms. Unsigned numbers are always
positive.
Floating point numbers are real numbers. It has 6 digits of precision. These numbers
are denoted by keyword float. When accuracy of floating point number
is insufficient , we use double keyword, it has 14 digits precision. To extend precision
further , we use long double.
It is used to specify type of function. When function does not return any value and if
there is empty parameter list
It is declared using keyword char. It stores single character item.
Integer Type
Vijayalaxmi D Wakode
Floating Point Type
Void Type
Character Type
Storage space requirement
Type
Size Range
short int 8 bits(1 byte) -128 to 127
int or signed int 16 bits(2 bytes) -32768 to 32767
Unsigned int 16 bits(2 bytes) 0 to 65535
Long int 32 bits(4 bytes) -2,147,483,648 to 2,147,483,648
Unsigned long int 32 bits(4 bytes) 0 to 4,294,967,295
Float 32 bits(4 bytes) 2^32
Double 64 bits(8 bytes) 2^64
Long double 80 bits(10 bytes) 2^80
Char 8 bits(1 byte) -128 to 127
Vijayalaxmi D Wakode
Table 1.2 Primary data types in C
1.4 Variables in C
• A variable is used to store data. It tells compiler variable name and data type of
variable.
Declaration : datatype identifier;
e.g. int x,y,z;
Converting lower type to higher type and vice versa, is known as type conversion.
Lower type is automatically converted into higher type
It is the process of local conversion. Its also known as type casting
Syntax : (type name) expression;
Type name is standard data type in c
Vijayalaxmi D Wakode
Type Conversion
a) Implicit Conversion
b)Explicit Conversion
1.5 Input and Output in C
Vijayalaxmi D Wakode
fig.1.3 input/output function in C
Format specifiers
symbol use
%d integer
%f Float value
%c Character value
%s String value
%u Unsigned integer value
%ld Long int
Vijayalaxmi D Wakode
1.6 Structure of C Program
Documentation Section
Link Section
Definition Section
Global Declaration Section
Main()
{
Declaration Part;
Executable Part;
}
Subprogram Section :
Function 1, Function 2, Function 3 Vijayalaxmi D Wakode

More Related Content

What's hot

Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
vinay arora
 

What's hot (20)

Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
C functions
C functionsC functions
C functions
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
 
c-programming
c-programmingc-programming
c-programming
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Strings in c language
Strings in  c languageStrings in  c language
Strings in c language
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
History of C Programming Language
History of C Programming LanguageHistory of C Programming Language
History of C Programming Language
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Array in c++
Array in c++Array in c++
Array in c++
 
introduction to c language
 introduction to c language introduction to c language
introduction to c language
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 

Viewers also liked

Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
SINGH PROJECTS
 
Lecture 2 history_of_c
Lecture 2 history_of_cLecture 2 history_of_c
Lecture 2 history_of_c
eShikshak
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
shalini392
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
History Of Computer
History Of ComputerHistory Of Computer
History Of Computer
guest420b9d
 

Viewers also liked (20)

INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
 
programming c language.
programming c language. programming c language.
programming c language.
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Uses of computers
Uses of computersUses of computers
Uses of computers
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Lecture 2 history_of_c
Lecture 2 history_of_cLecture 2 history_of_c
Lecture 2 history_of_c
 
C++ history session 00 history
C++ history session 00   historyC++ history session 00   history
C++ history session 00 history
 
C vs c++
C vs c++C vs c++
C vs c++
 
Victorian Crisis in Tennyson’s "Lotos Eaters"
Victorian Crisis in Tennyson’s "Lotos Eaters"Victorian Crisis in Tennyson’s "Lotos Eaters"
Victorian Crisis in Tennyson’s "Lotos Eaters"
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
Computer History
Computer HistoryComputer History
Computer History
 
Array in c language
Array in c languageArray in c language
Array in c language
 
C language ppt
C language pptC language ppt
C language ppt
 
History Of Computer
History Of ComputerHistory Of Computer
History Of Computer
 
Generations of computer
Generations of computerGenerations of computer
Generations of computer
 
Learning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageLearning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C Language
 
GENERATION OF COMPUTERS.
GENERATION OF COMPUTERS.GENERATION OF COMPUTERS.
GENERATION OF COMPUTERS.
 

Similar to fundamentals of c

Similar to fundamentals of c (20)

M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
C language
C languageC language
C language
 
Msc prev completed
Msc prev completedMsc prev completed
Msc prev completed
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updated
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Basics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest WayBasics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest Way
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming language
 
All C ppt.ppt
All C ppt.pptAll C ppt.ppt
All C ppt.ppt
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
C programming.pdf
C programming.pdfC programming.pdf
C programming.pdf
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Funa-C.ppt
Funa-C.pptFuna-C.ppt
Funa-C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).ppt
 

Recently uploaded

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 

Recently uploaded (20)

UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 

fundamentals of c

  • 1. 1.1 History of C Language Language Name Year of development Description ALGOL 60 1960 TOO ABSTRACT AND TOO SHORT CPL 1963 COMBINED P.L BCPL 1967 USED TO WRITE SYSTEM S/W. WAS NOT SO POWERFUL. B 1970 MACHINE DEPENDENT C 1972 GENERAL PURPOSE,COMPILED, STRUCTURED P.L, WITH UNIX O.S - ‘C’ LANGUAGE WAS DEVELOPED BY ‘DENNIS RITCHIE’ AT AT &T BELL LABORATORY IN 1972. Vijayalaxmi D Wakode
  • 2. Importance of C 1. It is robust language whose rich set of built in functions and operators can be used to write any complex program. 2. The language is very well suited from writing both system s/w and business package. We can also write compilers . 3. We can also write structural programs using C language. Character Set of C LETTERS A-Z, a-z DIGITS 0-9 SPECIAL CHARACTER _ ,! , etc. WHITE SPACES tab , enter , etc. The white spaces are ignored by compiler unless they are part of strings. Vijayalaxmi D Wakode
  • 3. 1.2 TOKENS IN C • To form a program i.e. set of executable statement , we need grammar. Like all language , C language also has its own rules and grammar known as syntactic rules / syntax. • The smallest individual unit in a program is known as ‘Token’. e.g. int, char, float, do , etc Num , hello, world, etc e.g. 10,5, 90.11, etc e.g. + , - , * , %,/, etc e.g. “Hello This is 1st lecture” e.g. {},[], etc Vijayalaxmi D Wakode
  • 4. i) Keywords • A keyword is a reserved word whose meaning can’t be changed by user. • Keyword serves as a basic building block for program design and development. The keywords must be written in ‘Lower Case’ , they have predefined meaning . • The C language consists of 32 keywords. Table 1.1 Keywords in ANSI C Vijayalaxmi D Wakode
  • 5. ii)Identifier • The words other than the keywords that are used in C program are known as ‘Identifiers’. These are the names that can be given to various program elements as variable, function, etc. • Identifier is user defined name. • The language identifies only 1st 32 characters as the identifiers. Naming rules for identifier a) First letter of identifier should not start with a digit b) Upper case and lower case letters are different c) The keyword name can’t be identifier d) White spaces and special symbols except underscore( _ ) are not allowed Vijayalaxmi D Wakode
  • 6. iii) Constants • In C language , the constants are referred to fixed values that don’t change during program execution. Figure 1.1: Types of constants in C Vijayalaxmi D Wakode
  • 7. a)Integer Constants • Decimal Integers : consists of a set of digits 0 to 9 preceded by an optional + or – sign. Spaces, commas and non digit characters are not permitted between digits. e.g. 12, -44 , 787878 • Octal Integers : consists of any combination of digits from 0 to 7 with prefix O. e.g. O26, O22 , O7 • Hexadecimal Integers : it is preceded by OX or Ox, they may contain alphabets from A to F(10-15) or a to f(10-15) • The quantities that are represented by numbers containing fractional parts are called real or floating point constants. These quantities are represented by numbers containing fractional parts like 98.72. e.g. 0.0023, -9.8 b)Real Constants Vijayalaxmi D Wakode
  • 8. c) single character constants • These constants are of a single character may be an alphabet, digit or special symbol that is enclosed in a pairs of single quotation marks . e.g. ‘x’ , ‘12’ , ‘ . ’ , etc. • These consists of the sequence of characters that are enclosed within a pairs of a double quotation marks. e.g. “Introduction of C” , “XYZ 123 ” , etc. • In C , every string is terminated by ‘0’ . It is null character that is automatically added to the string by the compiler . It is backslash character constant. These are also known as escape sequence character . d) string character constants Vijayalaxmi D Wakode
  • 9. Escape sequence characters • Backslash used in front of these characters tells the compiler to escape from regular behavior and perform the desired function. • List of the other such characters is as shown n new line b backspace t horizontal space o null character r carriage return • The constants can be defined in 2 ways in program. -we can give a direct value that is used as constant. E.g. int a=10. -we can use #define preprocessor directive. E.g. #define PI 3.14 Vijayalaxmi D Wakode
  • 10. iv)Operator • A operator is defined as a symbol that tells the computer to perform certain mathematical or logical manipulation. • These are basically used to manipulate data . • C provides a rich set of built in operators. Vijayalaxmi D Wakode
  • 11. a) Arithmetic Operator • The C language supports various different arithmetic operators as +,-,/,*,%. The % is known as modulus operator used to find remainder of an expression. Integer Arithmetic • An arithmetic operation performed on 2 whole numbers/ integers . It always gives an integer result. In integer division the fractional part is truncated. Floating point Arithmetic • An arithmetic operation performed on 2 real / fractional numbers. It results can be truncated according to the properties requirement. The remainder operator (%) is not applicable for floating point arithmetic operands. Mixed mode Arithmetic • An arithmetic operation performed on 1 of real operands and another integer operand. Its result is always real. Vijayalaxmi D Wakode
  • 12. b)Comparison Operator • These operators are also known as relational operator. These are used to compare 2 quantities. The value of relational expression is either 0/1. If expression is true then 1 and 0 if its false • Syntax : exp1 relational operator exp2. e.g. -90 > 0 false(0), 11> 7+2 true(1) • Relational operator are used in decision making statements in C language. symbols meaning < Less than <= Less than equal to > Greater than >= Greater than equal to == Equal to != Not equal to Vijayalaxmi D Wakode
  • 13. c) Logical Operator • The language supports 3 kinds of logical operator. These are basically used when we want to use more than 1 condition and make certain decision. i)Logical AND (&&) ii)Logical OR(||) iii) Logical NOT(!) A B o/p : A && B 0 0 0 0 1 0 1 0 0 1 1 1 A B o/p : A|| B 0 0 0 0 1 1 1 0 1 1 1 1 A o/p: !A 0 1 1 0 Vijayalaxmi D Wakode
  • 14. v) Assignment Operator • These are used to assign the result of an expression to a variable / it can also be used to assign value to a variable. • In case of assignment operator L.H.S must be a variable but R.H.S can be expression or any constant value. e.g. A = 2, x = A + 3 • C language also supports set of short hand assignment operator . Operator Stmt with simple assign operator Stmt with shorthand property += a=a+1 a+=1 -= a=a-1 a-=1 *= a=a*1 a*=1 /= a=a/1 a/=1 %= a=a%1 a%=1 Vijayalaxmi D Wakode
  • 16. vi)Conditional Operator • Conditional operator operates 3 conditions, hence also known as ternary operator. Syntax : expr1 ? expr2 : expr3; e.g. (5>10)? printf(“5”); : printf(“10”); • Expr1 is evaluated first. Its value is either true or false . If it is true the expr2 is evaluated and this becomes value of complete expr. If expr1 is false, then expr3 is evaluated and this becomes the value of complete expr. Only 1 of the expr’s i.e expr2/ expr3 will be evaluated but not both. • Conditional operator is short form of if…else structure. Vijayalaxmi D Wakode
  • 17. vii)Bitwise Operator • C language also supports various bitwise operator that operates at bit level. These are used to test bits them in left / right. • The o/p of bitwise AND is 1 if all the corresponding bits of all operands is 1. • The o/p of bitwise OR is 1 if at least one corresponding bits of all operands is 1. • The o/p of bitwise XOR is 1 if the corresponding bits of 2 operands are opposite. • Bitwise complement operator is an unary operator. It changes 1 to 0(condition). operator meaning & Bitwise and | Bitwise or ~ Complement ^ Bitwise exclusive or << Shift left >> Shift right Vijayalaxmi D Wakode
  • 18. viii) Special Operator • C language also supports some special operators as comma, sizeof(), pointer operator (*), member selection operator( . ) i) comma operator : It is used to separate variables. e.g. int a,b,c; ii) sizeof operator : The sizeof is a compile time operator that returns the numbers of bytes the operand occupies. The operand may be a variable , constant or datatype qualifier. e.g. int x,y; y=sizeof(x); o/p: y = 2 Vijayalaxmi D Wakode
  • 19. 1.3 Data Types in C • Datatype means type of data which we are going to give to computer for processing. It basically used to calculate the memory requirement. fig. 1.2. Data types in C Vijayalaxmi D Wakode
  • 20. Primary Data Types These are the built in and fundamental data types . Integers are whole numbers i.e. numbers without decimal point. All these data types short int, int, long int have signed & unsigned forms. Unsigned numbers are always positive. Floating point numbers are real numbers. It has 6 digits of precision. These numbers are denoted by keyword float. When accuracy of floating point number is insufficient , we use double keyword, it has 14 digits precision. To extend precision further , we use long double. It is used to specify type of function. When function does not return any value and if there is empty parameter list It is declared using keyword char. It stores single character item. Integer Type Vijayalaxmi D Wakode Floating Point Type Void Type Character Type
  • 21. Storage space requirement Type Size Range short int 8 bits(1 byte) -128 to 127 int or signed int 16 bits(2 bytes) -32768 to 32767 Unsigned int 16 bits(2 bytes) 0 to 65535 Long int 32 bits(4 bytes) -2,147,483,648 to 2,147,483,648 Unsigned long int 32 bits(4 bytes) 0 to 4,294,967,295 Float 32 bits(4 bytes) 2^32 Double 64 bits(8 bytes) 2^64 Long double 80 bits(10 bytes) 2^80 Char 8 bits(1 byte) -128 to 127 Vijayalaxmi D Wakode Table 1.2 Primary data types in C
  • 22. 1.4 Variables in C • A variable is used to store data. It tells compiler variable name and data type of variable. Declaration : datatype identifier; e.g. int x,y,z; Converting lower type to higher type and vice versa, is known as type conversion. Lower type is automatically converted into higher type It is the process of local conversion. Its also known as type casting Syntax : (type name) expression; Type name is standard data type in c Vijayalaxmi D Wakode Type Conversion a) Implicit Conversion b)Explicit Conversion
  • 23. 1.5 Input and Output in C Vijayalaxmi D Wakode fig.1.3 input/output function in C
  • 24. Format specifiers symbol use %d integer %f Float value %c Character value %s String value %u Unsigned integer value %ld Long int Vijayalaxmi D Wakode
  • 25. 1.6 Structure of C Program Documentation Section Link Section Definition Section Global Declaration Section Main() { Declaration Part; Executable Part; } Subprogram Section : Function 1, Function 2, Function 3 Vijayalaxmi D Wakode