SlideShare a Scribd company logo
1 of 24
Download to read offline
Introduction to Computers and
Programming (CSC103)
Lecture 03
Introduction to C Language
 C is developed at AT&T’s Bell Laboratories of USA in
1972
 Designed and written by Dennis Ritchie
 Gained popularity and support in late 1970
 Most of the Operating Systems are written in C
 American National Standards Institute (ANSI) formed an
ANSI C committee X3J11 in 1983
 In 1990, first official ANSI standard definition was
published
 Why C?Why not C++, Java or C#?
 First have to learn basic learning elements of a language
2
Programming
 Computers are dumb machines;They are told what to do
 e.g. How to add two numbers, how to find the average etc
 Basic operations of a computer system form instruction
set
 Solving a problem
 Express the solution in set of instructions
 Program: collection of instructions to solve a specific
problem
 Algorithm: the approach or method that is used to solve a
problem.
3
 For example:A program that tests if a number is even or
odd
 Program:The set of statements that solves the problem
 Algorithm:The method that is used to test if a number is even
or odd
 To solve a problem, first express the solution in terms of
an algorithm
 Then develop a program that implements that algorithm
4
 Algorithm for solving even and odd number problem:
1) Get the number
2) Divide the number by two (2)
3) If remainder is zero (0), the number is even
4) Otherwise, the number is odd
 This algorithm is then implemented in a specific language
like C, C++, Java,Visual Basic etc
5
Learning English Language vs C Language
6
C Character Set
 Valid alphabets, numbers and special symbols allowed in C
7
My First C Program – with a problem
main()
{
printf("My First C Program");
}
Output:
Compilation Error
8
My First C Program – correction
#include<stdio.h>
void main()
{
printf("My First C Program");
}
Output
My First C Program
9
Compilation & Execution
 Edit
 Program is first typed into a file
 A text editor like notepad is used
 Save the file with a valid name along with .c extension e.g. prog1.c
 This program is known as source program
 Preprocessor
 Removes comments
 Handles directives for source file inclusions, definitions etc
 Compile
 It examines each program statement in the source program
 Checks the syntax and semantics of the language
 Any error is notified to the user
 Correct the error and restart the compilation process
 Two types of errors
 Syntactic errors (when an invalid statement is written in program)
 Semantic errors (logical error)
10
 If there is no error, the compiler translates each
statement into assembly language form.
 Then the assembly language statements are translated
into machine instructions using another program called
assembler
 Sometimes assembler is part of the compiler
 The assembler translated each assembly language
statement into a binary format known as object code
 Object code is written into another file having extension of
”obj” e.g. prog1.obj
 Now the program is ready to be linked
11
 Link
 The purpose of linking is to get the program into final form for
execution
 It links other programs if the compiler have used before
 Programs from library are also linked
 The process of compiling and linking is called building
 The final linked file, called executable object code is stored in
another file
 with extension “.exe”
 Execute
 To subsequently execute the program type the name of the
executable file
 Loading is the process of placing the program in computer’s memory
and initiating it’s execution
12
Constants, Variables and Keywords
 The alphabets, digits and special symbols when properly
combined form constants, variables and keywords
 A constant is an entity that doesn’t change
 A variable is an entity that may change
 In a program, we do different calculations
 The results of these calculations are stored in computers
memory
 To make the retrieval of these values easy, these memory
locations are given names
 Since the values stored in these memory locations may change
 The names given to these memory locations are called variables
13
Example
 For example 3 is stored in a memory location
 The name of this memory location is x
 Then we assign a new value 5 to this memory location
 This will overwrite the earlier value 3, as a memory
location can hold one value at a time
 Since the memory location x can hold different values at
different times
 x is known as a variable
 Value 3 or 5 do not change, hence are known as
constants
14
Types of C Constants
 C constants can be divided into two major categories
 Primary Constants
 Secondary Constants
15
Rules for Integer Constants
 An integer constant must have at least one digit
 It must not have a decimal point
 It can be either positive or negative
 If no sign precedes an integer constant it is assumed to be
positive
 No commas or blanks are allowed within an integer
constant
 The allowable range for constants is -32768 to 32767
 e.g. 430, +635, -4090
16
Rules for Real or Float Constants
 The float constants could be written in two forms
 Fractional form
 Exponential form
Following are the rules for float constants
 A float constant must have at least one digit
 It must have a decimal point
 It could be either positive or negative
 Default sign is positive
 No commas or blanks are allowed within a float constant
 e.g. +534.63, 834.0, -27.50
17
Cont…
 In exponential form, the float constant is represented in two
parts.The part appearing before e is called mantissa, whereas
the part after e is called exponent
Following are the rules for exponential form of float constant
 The mantissa and exponential parts should be separated by e
 The mantissa part may have a positive or negative sign
 Default sign of mantissa part is positive
 The exponent must have at least one digit, which must be a
positive or negative integer. Default sign is positive
 Range of float constant in exponential form is -3.4e38 to
3.4e38 (which is 3.4 x 1038)
 e.g. 363e5,+4.2e7, 9.4e-4
18
Rules for Character Constants
 A character constant is a single alphabet, a single digit or
a single special symbol enclosed within single inverted
commas
 Both inverted commas should point to the left
 For example, ’A’ is a valid character constant whereas ‘A’
is not
 The maximum length of a character constant can be 1
character
 e.g.‘A’,‘e’,‘5’
19
Types of C Variables
 Variable names are given to a location in memory
 These locations can contain integer, float or character
constants
 Types of variables depends on the types of constants that
it can handle
 A particular type of variable can hold only the same type
of constant
 e.g. an integer variable can hold only an integer constant,
a float variable can hold a float constant and a character
variable can hold a character constant
20
Constructing a Variable Name
 Constructing the variable names of all types the same set
of rules apply. These rules are given below:
 A variable name is any combination of 1 to 31 alphabets, digits
or underscores
 Some compilers allow variable names of length 247 characters
 Do not create unnecessary long variable names
 The first character in the variable name must be an alphabet or
underscore
 No commas or blanks are allowed within a variable name
 No special characters other than underscore can be used
 e.g. si_int, age_max, value80
21
 C compiler distinguish between the variable names by
making it compulsory to declare the type of any variable
you want to use in a program
 Following are some type declaration examples
int sum;
float salary;
char name;
22
Addition Example
#include<stdio.h>
void main()
{
int sum;
sum = 30 + 40;
printf("The sum of 30 and 40 is %dn", sum);
}
23
C Keywords
 Keywords are the words whose meaning has already been explained to the
C compiler
 The keywords cannot be used as variable names
 The keywords are also called “Reserved words”
 There are 32 keywords available in C
24

More Related Content

What's hot

Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 
Language processors
Language processorsLanguage processors
Language processors
eShikshak
 

What's hot (20)

Chap 1-language processor
Chap 1-language processorChap 1-language processor
Chap 1-language processor
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Language processors
Language processorsLanguage processors
Language processors
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer program
 
Software tools
Software toolsSoftware tools
Software tools
 
Compiler design Introduction
Compiler design IntroductionCompiler design Introduction
Compiler design Introduction
 
Programming
ProgrammingProgramming
Programming
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Introduction to compilers
Introduction to compilersIntroduction to compilers
Introduction to compilers
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Principles of programming
Principles of programmingPrinciples of programming
Principles of programming
 
Assembly language
Assembly languageAssembly language
Assembly language
 
Compiler1
Compiler1Compiler1
Compiler1
 
Language processors
Language processorsLanguage processors
Language processors
 
Language processors
Language processorsLanguage processors
Language processors
 

Viewers also liked

Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
hassaanciit
 
Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2
hassaanciit
 
Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02
hassaanciit
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
Jussi Pohjolainen
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
salmankhan570
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1
ahfiki
 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentation
sameerraaj
 

Viewers also liked (17)

Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
 
Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2Introduction to Computer and Programing - Lab2
Introduction to Computer and Programing - Lab2
 
Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02Introduction to Computer and Programming - Lecture 02
Introduction to Computer and Programming - Lecture 02
 
PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010PowerPoint for Introduction to Office 2010
PowerPoint for Introduction to Office 2010
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01
 
Using Computer Keyboard
Using Computer KeyboardUsing Computer Keyboard
Using Computer Keyboard
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
Ms word 2010 by sachin sharma
Ms word 2010 by sachin sharmaMs word 2010 by sachin sharma
Ms word 2010 by sachin sharma
 
MS OFFICE 2010 VS 2007
MS OFFICE 2010 VS 2007MS OFFICE 2010 VS 2007
MS OFFICE 2010 VS 2007
 
An introduction to microsoft office 2007 lecture
An introduction to microsoft office 2007 lectureAn introduction to microsoft office 2007 lecture
An introduction to microsoft office 2007 lecture
 
Database Design Slide 1
Database Design Slide 1Database Design Slide 1
Database Design Slide 1
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
CS101- Introduction to Computing- Lecture 33
CS101- Introduction to Computing- Lecture 33CS101- Introduction to Computing- Lecture 33
CS101- Introduction to Computing- Lecture 33
 
Introduction to microsoft word 2007
Introduction to microsoft word 2007Introduction to microsoft word 2007
Introduction to microsoft word 2007
 
Database management system presentation
Database management system presentationDatabase management system presentation
Database management system presentation
 

Similar to Introduction to Computer and Programming - Lecture 03

component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
AnisZahirahAzman
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
Aami Kakakhel
 

Similar to Introduction to Computer and Programming - Lecture 03 (20)

Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
 
C Language
C LanguageC Language
C Language
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
qb unit2 solve eem201.pdf
qb unit2 solve eem201.pdfqb unit2 solve eem201.pdf
qb unit2 solve eem201.pdf
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
C language
C language C language
C language
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
 
C language ppt
C language pptC language ppt
C language ppt
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 
Cnotes
CnotesCnotes
Cnotes
 
Ch02
Ch02Ch02
Ch02
 
Module 1 PCD.docx
Module 1 PCD.docxModule 1 PCD.docx
Module 1 PCD.docx
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
 

More from hassaanciit

Circuits Lecture 5 with examples
Circuits Lecture 5 with examplesCircuits Lecture 5 with examples
Circuits Lecture 5 with examples
hassaanciit
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
hassaanciit
 
Ex 1 3_fsc_part1
Ex 1 3_fsc_part1Ex 1 3_fsc_part1
Ex 1 3_fsc_part1
hassaanciit
 
Islamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefsIslamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefs
hassaanciit
 
Islamic Studies - Concepts About Religion
Islamic Studies - Concepts About ReligionIslamic Studies - Concepts About Religion
Islamic Studies - Concepts About Religion
hassaanciit
 
Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)
hassaanciit
 
Islamic Studies - Course Outline
Islamic Studies - Course OutlineIslamic Studies - Course Outline
Islamic Studies - Course Outline
hassaanciit
 

More from hassaanciit (8)

Circuits Lecture 5 with examples
Circuits Lecture 5 with examplesCircuits Lecture 5 with examples
Circuits Lecture 5 with examples
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
 
Ex 1 3_fsc_part1
Ex 1 3_fsc_part1Ex 1 3_fsc_part1
Ex 1 3_fsc_part1
 
Islamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefsIslamic Studies - Fundamental beliefs
Islamic Studies - Fundamental beliefs
 
Islamic Studies - Concepts About Religion
Islamic Studies - Concepts About ReligionIslamic Studies - Concepts About Religion
Islamic Studies - Concepts About Religion
 
Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)Islamic Studies - Lecture#1 (Religion)
Islamic Studies - Lecture#1 (Religion)
 
Islamic Studies - Course Outline
Islamic Studies - Course OutlineIslamic Studies - Course Outline
Islamic Studies - Course Outline
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Introduction to Computer and Programming - Lecture 03

  • 1. Introduction to Computers and Programming (CSC103) Lecture 03
  • 2. Introduction to C Language  C is developed at AT&T’s Bell Laboratories of USA in 1972  Designed and written by Dennis Ritchie  Gained popularity and support in late 1970  Most of the Operating Systems are written in C  American National Standards Institute (ANSI) formed an ANSI C committee X3J11 in 1983  In 1990, first official ANSI standard definition was published  Why C?Why not C++, Java or C#?  First have to learn basic learning elements of a language 2
  • 3. Programming  Computers are dumb machines;They are told what to do  e.g. How to add two numbers, how to find the average etc  Basic operations of a computer system form instruction set  Solving a problem  Express the solution in set of instructions  Program: collection of instructions to solve a specific problem  Algorithm: the approach or method that is used to solve a problem. 3
  • 4.  For example:A program that tests if a number is even or odd  Program:The set of statements that solves the problem  Algorithm:The method that is used to test if a number is even or odd  To solve a problem, first express the solution in terms of an algorithm  Then develop a program that implements that algorithm 4
  • 5.  Algorithm for solving even and odd number problem: 1) Get the number 2) Divide the number by two (2) 3) If remainder is zero (0), the number is even 4) Otherwise, the number is odd  This algorithm is then implemented in a specific language like C, C++, Java,Visual Basic etc 5
  • 6. Learning English Language vs C Language 6
  • 7. C Character Set  Valid alphabets, numbers and special symbols allowed in C 7
  • 8. My First C Program – with a problem main() { printf("My First C Program"); } Output: Compilation Error 8
  • 9. My First C Program – correction #include<stdio.h> void main() { printf("My First C Program"); } Output My First C Program 9
  • 10. Compilation & Execution  Edit  Program is first typed into a file  A text editor like notepad is used  Save the file with a valid name along with .c extension e.g. prog1.c  This program is known as source program  Preprocessor  Removes comments  Handles directives for source file inclusions, definitions etc  Compile  It examines each program statement in the source program  Checks the syntax and semantics of the language  Any error is notified to the user  Correct the error and restart the compilation process  Two types of errors  Syntactic errors (when an invalid statement is written in program)  Semantic errors (logical error) 10
  • 11.  If there is no error, the compiler translates each statement into assembly language form.  Then the assembly language statements are translated into machine instructions using another program called assembler  Sometimes assembler is part of the compiler  The assembler translated each assembly language statement into a binary format known as object code  Object code is written into another file having extension of ”obj” e.g. prog1.obj  Now the program is ready to be linked 11
  • 12.  Link  The purpose of linking is to get the program into final form for execution  It links other programs if the compiler have used before  Programs from library are also linked  The process of compiling and linking is called building  The final linked file, called executable object code is stored in another file  with extension “.exe”  Execute  To subsequently execute the program type the name of the executable file  Loading is the process of placing the program in computer’s memory and initiating it’s execution 12
  • 13. Constants, Variables and Keywords  The alphabets, digits and special symbols when properly combined form constants, variables and keywords  A constant is an entity that doesn’t change  A variable is an entity that may change  In a program, we do different calculations  The results of these calculations are stored in computers memory  To make the retrieval of these values easy, these memory locations are given names  Since the values stored in these memory locations may change  The names given to these memory locations are called variables 13
  • 14. Example  For example 3 is stored in a memory location  The name of this memory location is x  Then we assign a new value 5 to this memory location  This will overwrite the earlier value 3, as a memory location can hold one value at a time  Since the memory location x can hold different values at different times  x is known as a variable  Value 3 or 5 do not change, hence are known as constants 14
  • 15. Types of C Constants  C constants can be divided into two major categories  Primary Constants  Secondary Constants 15
  • 16. Rules for Integer Constants  An integer constant must have at least one digit  It must not have a decimal point  It can be either positive or negative  If no sign precedes an integer constant it is assumed to be positive  No commas or blanks are allowed within an integer constant  The allowable range for constants is -32768 to 32767  e.g. 430, +635, -4090 16
  • 17. Rules for Real or Float Constants  The float constants could be written in two forms  Fractional form  Exponential form Following are the rules for float constants  A float constant must have at least one digit  It must have a decimal point  It could be either positive or negative  Default sign is positive  No commas or blanks are allowed within a float constant  e.g. +534.63, 834.0, -27.50 17
  • 18. Cont…  In exponential form, the float constant is represented in two parts.The part appearing before e is called mantissa, whereas the part after e is called exponent Following are the rules for exponential form of float constant  The mantissa and exponential parts should be separated by e  The mantissa part may have a positive or negative sign  Default sign of mantissa part is positive  The exponent must have at least one digit, which must be a positive or negative integer. Default sign is positive  Range of float constant in exponential form is -3.4e38 to 3.4e38 (which is 3.4 x 1038)  e.g. 363e5,+4.2e7, 9.4e-4 18
  • 19. Rules for Character Constants  A character constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas  Both inverted commas should point to the left  For example, ’A’ is a valid character constant whereas ‘A’ is not  The maximum length of a character constant can be 1 character  e.g.‘A’,‘e’,‘5’ 19
  • 20. Types of C Variables  Variable names are given to a location in memory  These locations can contain integer, float or character constants  Types of variables depends on the types of constants that it can handle  A particular type of variable can hold only the same type of constant  e.g. an integer variable can hold only an integer constant, a float variable can hold a float constant and a character variable can hold a character constant 20
  • 21. Constructing a Variable Name  Constructing the variable names of all types the same set of rules apply. These rules are given below:  A variable name is any combination of 1 to 31 alphabets, digits or underscores  Some compilers allow variable names of length 247 characters  Do not create unnecessary long variable names  The first character in the variable name must be an alphabet or underscore  No commas or blanks are allowed within a variable name  No special characters other than underscore can be used  e.g. si_int, age_max, value80 21
  • 22.  C compiler distinguish between the variable names by making it compulsory to declare the type of any variable you want to use in a program  Following are some type declaration examples int sum; float salary; char name; 22
  • 23. Addition Example #include<stdio.h> void main() { int sum; sum = 30 + 40; printf("The sum of 30 and 40 is %dn", sum); } 23
  • 24. C Keywords  Keywords are the words whose meaning has already been explained to the C compiler  The keywords cannot be used as variable names  The keywords are also called “Reserved words”  There are 32 keywords available in C 24