SlideShare a Scribd company logo
1 of 29
Download to read offline
 KIIT 2014
Tokens in C
 KIIT 2014
Objectives
After completing this lesson, you should be able to do the following:
• Identify various tokens in C language
• List and describe various data types
• List the uses of variables
• Declare and initialize variables
• Define constants and literals
• Use of storage classes
• Identify and use of operators
 KIIT 2014
Tokens in C
A C program consists of various tokens and a token is either a
keyword, an identifier, a constant, a string literal, or a symbol.
For example, the following C statement consists of five tokens::
• Keyword
• Identifier
• Constant
• String Literals
• Symbols
 KIIT 2014
Token - Example
printf("Hello, World! n");
C statement consists of five tokens:
The individual tokens are:
printf
( "
Hello, World! n"
);
 KIIT 2014
Semicolons
In C program, the semicolon is a statement terminator.
Example:
printf("Hello, World! n");
return 0;
 KIIT 2014
Comments
Comments are like helping text in your C program and they are
ignored by the compiler.
Example:
/* my first program in C */
 KIIT 2014
Identifiers
Identifiers are used for:
• Naming a variable
• Providing a convention for variable names:
– Must start with a letter
– Can include letters or numbers
– Can’t include special characters such as dollar sign,
percentage and pound sign
– Must not be keywords
mohd zara abc move_name a_123
myname50 _temp j a23b9 retVal
 KIIT 2014
Keywords
The following list shows the reserved words in C:
auto else long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double
 KIIT 2014
Whitespace in C
A line containing only whitespace, possibly with a
comment, is known as a blank line, and a C compiler
totally ignores it.
fruit = apples + oranges; // get the total fruit
int age;
 KIIT 2014
Data Types in C
Refer to an extensive system used for declaring variables
or functions of different types. The type of a variable
determines how much space it occupies in storage and
how the bit pattern stored is interpreted.
The types in C can be classified as follows:
• Basic Types
• Enumerated Types
• The Type Void
• Derived Types
 KIIT 2014
Integer Types
Standard integer types with its storage sizes and value
ranges:
 KIIT 2014
Floating - Point Types
Standard floating - point types with its storage sizes and
value ranges:
 KIIT 2014
C - Variables
A variable is nothing but a name given to a storage area
that programs can manipulate.
Syntax:
Example:
type variable_list;
int i, j, k;
char c, ch;
float f, salary;
double d;
 KIIT 2014
Variable Initialization
Variables can be initialized (assigned an initial value) in their
declaration. The initializer consists of an equal sign followed
by a constant expression as follows:
Syntax:
Example:
type variable_name = value;
extern int d = 3, f = 5; // declaration of d and
f.
int d = 3, f = 5; // definition and initializing d
and f.
byte z = 22; // definition and initializes z.
char x = 'x'; // the variable x has the value 'x'.
 KIIT 2014
Variable Declaration
A variable declaration provides assurance to the compiler
that there is one variable existing with the given type and
name so that compiler proceed for further compilation
without needing complete detail about the variable.
A variable declaration has its meaning at the time of
compilation only, compiler needs actual variable
declaration at the time of linking of the program.
 KIIT 2014
Variable Declaration - Example
#include <stdio.h>
// Variable declaration:
extern int a, b;
extern int c;
extern float f;
int main ()
{
/* variable definition: */
int a, b;
int c;
float f;
/* actual initialization */
a = 10;
b = 20;
c = a + b;
printf("value of c : %d n", c);
f = 70.0/3.0;
printf("value of f : %f n", f);
return 0;
}
 KIIT 2014
// function declaration
int func();
int main()
{
// function call
int i = func();
}
// function definition
int func()
{
return 0;
}
 KIIT 2014
Variable Types
Based on the scope of the variable, can
be classified into:
• Local Variable
• Global Variable
 KIIT 2014
Local Variable
• Has local / limited scope
• Is accessible only within a function or block in which
it is declared
• Has higher precedence over global variable
 KIIT 2014
Local Variable
• Variables declared inside outer block are visible or meaningful only
inside outer block
• Similarly variables declared inside inner block are visible or meaningful
only inside inner block
• Variables declared inside inner block are not accessed by outer block
#include<stdio.h>
void main()
{
int var1=10;
{
int var2 = 20;
printf("%d %d",var1,var2);
}
printf("%d %d",var1,var2);
}
 KIIT 2014
Global Variable
• Has global scope and available throughout the
program
• Is also visible inside function, provided that it should
not be re-declared
• Can be accessed from any function
 KIIT 2014
Global Variable
• Inner block variables declared in outer block acts as “Global Variable”
#include<stdio.h>
int var=10;
void message();
void main()
{
int var=20;
{
int var = 30;
printf("%d ",var);
}
printf("%d ",var);
message();
}
void message()
{
printf("%d ",var);
}
 KIIT 2014
Attributes of Variable
Fundamentals attributes of C variable :
• Name of Variable
• Values inside Variable
• Address of Variable
• Size of Variable
• Type of Variable
 KIIT 2014
Constants and Literals
• The constants refer to fixed values that the program
may not alter during its execution. These fixed values
are also called literals.
• The constants are treated just like regular variables
except that their values cannot be modified after
their definition.
– Integer Literals
– Floating point Literals
– Character Constants
– String Literals
 KIIT 2014
Character Literals
Character literals can be
• A plain character
• An escape sequence
 KIIT 2014
Escape Sequence
 KIIT 2014
String Literals
String literals or constants are enclosed in double quotes
""
Example:
There are two simple ways in C to define constants:
• Using #define preprocessor.
• Using const keyword
"hello, dear"
const type variable = value;
 KIIT 2014
Operators
C provide following types of operators:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Assignment Operators
 KIIT 2014
Summary
In this lesson, you should have learned how to:
• Identify various tokens in C language
• List and describe various data types
• List the uses of variables
• Declare and initialize variables
• Define constants and literals
• Identify and use of operators

More Related Content

Similar to C Programming Lesson 2.pdf (20)

unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
C programming language
C programming languageC programming language
C programming language
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
C language updated
C language updatedC language updated
C language updated
 
C language ppt
C language pptC language ppt
C language ppt
 
UNIT 1 NOTES.docx
UNIT 1 NOTES.docxUNIT 1 NOTES.docx
UNIT 1 NOTES.docx
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
C programming notes
C programming notesC programming notes
C programming notes
 
Storage classes
Storage classesStorage classes
Storage classes
 
Structure
StructureStructure
Structure
 
C programming
C programmingC programming
C programming
 
Basics of C porgramming
Basics of C porgrammingBasics of C porgramming
Basics of C porgramming
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
 
C programming language
C programming languageC programming language
C programming language
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
Programming in c plus plus3
Programming in c plus plus3Programming in c plus plus3
Programming in c plus plus3
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
 
C Language
C LanguageC Language
C Language
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

C Programming Lesson 2.pdf

  • 2.  KIIT 2014 Objectives After completing this lesson, you should be able to do the following: • Identify various tokens in C language • List and describe various data types • List the uses of variables • Declare and initialize variables • Define constants and literals • Use of storage classes • Identify and use of operators
  • 3.  KIIT 2014 Tokens in C A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens:: • Keyword • Identifier • Constant • String Literals • Symbols
  • 4.  KIIT 2014 Token - Example printf("Hello, World! n"); C statement consists of five tokens: The individual tokens are: printf ( " Hello, World! n" );
  • 5.  KIIT 2014 Semicolons In C program, the semicolon is a statement terminator. Example: printf("Hello, World! n"); return 0;
  • 6.  KIIT 2014 Comments Comments are like helping text in your C program and they are ignored by the compiler. Example: /* my first program in C */
  • 7.  KIIT 2014 Identifiers Identifiers are used for: • Naming a variable • Providing a convention for variable names: – Must start with a letter – Can include letters or numbers – Can’t include special characters such as dollar sign, percentage and pound sign – Must not be keywords mohd zara abc move_name a_123 myname50 _temp j a23b9 retVal
  • 8.  KIIT 2014 Keywords The following list shows the reserved words in C: auto else long switch break enum register typedef case extern return union char float short unsigned const for signed void continue goto sizeof volatile default if static while do int struct _Packed double
  • 9.  KIIT 2014 Whitespace in C A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it. fruit = apples + oranges; // get the total fruit int age;
  • 10.  KIIT 2014 Data Types in C Refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The types in C can be classified as follows: • Basic Types • Enumerated Types • The Type Void • Derived Types
  • 11.  KIIT 2014 Integer Types Standard integer types with its storage sizes and value ranges:
  • 12.  KIIT 2014 Floating - Point Types Standard floating - point types with its storage sizes and value ranges:
  • 13.  KIIT 2014 C - Variables A variable is nothing but a name given to a storage area that programs can manipulate. Syntax: Example: type variable_list; int i, j, k; char c, ch; float f, salary; double d;
  • 14.  KIIT 2014 Variable Initialization Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows: Syntax: Example: type variable_name = value; extern int d = 3, f = 5; // declaration of d and f. int d = 3, f = 5; // definition and initializing d and f. byte z = 22; // definition and initializes z. char x = 'x'; // the variable x has the value 'x'.
  • 15.  KIIT 2014 Variable Declaration A variable declaration provides assurance to the compiler that there is one variable existing with the given type and name so that compiler proceed for further compilation without needing complete detail about the variable. A variable declaration has its meaning at the time of compilation only, compiler needs actual variable declaration at the time of linking of the program.
  • 16.  KIIT 2014 Variable Declaration - Example #include <stdio.h> // Variable declaration: extern int a, b; extern int c; extern float f; int main () { /* variable definition: */ int a, b; int c; float f; /* actual initialization */ a = 10; b = 20; c = a + b; printf("value of c : %d n", c); f = 70.0/3.0; printf("value of f : %f n", f); return 0; }
  • 17.  KIIT 2014 // function declaration int func(); int main() { // function call int i = func(); } // function definition int func() { return 0; }
  • 18.  KIIT 2014 Variable Types Based on the scope of the variable, can be classified into: • Local Variable • Global Variable
  • 19.  KIIT 2014 Local Variable • Has local / limited scope • Is accessible only within a function or block in which it is declared • Has higher precedence over global variable
  • 20.  KIIT 2014 Local Variable • Variables declared inside outer block are visible or meaningful only inside outer block • Similarly variables declared inside inner block are visible or meaningful only inside inner block • Variables declared inside inner block are not accessed by outer block #include<stdio.h> void main() { int var1=10; { int var2 = 20; printf("%d %d",var1,var2); } printf("%d %d",var1,var2); }
  • 21.  KIIT 2014 Global Variable • Has global scope and available throughout the program • Is also visible inside function, provided that it should not be re-declared • Can be accessed from any function
  • 22.  KIIT 2014 Global Variable • Inner block variables declared in outer block acts as “Global Variable” #include<stdio.h> int var=10; void message(); void main() { int var=20; { int var = 30; printf("%d ",var); } printf("%d ",var); message(); } void message() { printf("%d ",var); }
  • 23.  KIIT 2014 Attributes of Variable Fundamentals attributes of C variable : • Name of Variable • Values inside Variable • Address of Variable • Size of Variable • Type of Variable
  • 24.  KIIT 2014 Constants and Literals • The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. • The constants are treated just like regular variables except that their values cannot be modified after their definition. – Integer Literals – Floating point Literals – Character Constants – String Literals
  • 25.  KIIT 2014 Character Literals Character literals can be • A plain character • An escape sequence
  • 27.  KIIT 2014 String Literals String literals or constants are enclosed in double quotes "" Example: There are two simple ways in C to define constants: • Using #define preprocessor. • Using const keyword "hello, dear" const type variable = value;
  • 28.  KIIT 2014 Operators C provide following types of operators: • Arithmetic Operators • Relational Operators • Logical Operators • Assignment Operators
  • 29.  KIIT 2014 Summary In this lesson, you should have learned how to: • Identify various tokens in C language • List and describe various data types • List the uses of variables • Declare and initialize variables • Define constants and literals • Identify and use of operators