SlideShare una empresa de Scribd logo
1 de 23
Variables, Datatype,
Constants, Keywords,
Comments, Rules for Writing
C program
Part 2
By: Er. Aman Kumar
Variables
• Variable is simply name given to memory
location which acts as placeholder or
container for storing data. It may help to think
of variables as a container for a value.
Data type
• We can store variables in our computer
memory. Since each type of data takes
different amount of memory, like integer takes
2 bytes, decimal numbers take 4 byte, and
SINGLE character takes 1 byte. So we have to
tell computer about the type of data we are
going to store in our variable
• Predefined/inbuilt :
These datatypes are inbuilt.
eg : char, int, float, double
• Drived Datatype
These datatypes are inherited from predefined
datatype. eg : arrays, pointer.
• Userdefined datatype : These are created by user
for his/her own purpose
• eg : typedef, enum, structure, union
Predefined Datatypes
Character set
• Character set: every character is assigned unique
number called character set. C/C++ follows ASCII
character set.
• ASCII: American standard code for information
interchange
• Here lowercase, uppercase characters (English),
special symbols, digits have been assigned unique
integer number.
• Total 256 characters are there.
• Range is: -128 to 127
• Here limitation is only English is used.
Identifiers
• Identifier is simply a name given to your
variable, class, union, structure, function, etc.
• Rules for creating valid identifiers:
• 1. An identifier can be any combination of
alphabets, digits, underscore.
• 2. Neither spaces nor special symbol other
then underscore can be used.
• 3. It won‘t begin with a digit
Declaration and initialization of
variable
• How to declare variable?
• Declaration of variable means specify data type
of variable and name assigned (identifier).
• 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.
• syntax :
datatype varible_name;
eg :
int a;
float b;
char c;
double first;
int i, j, k;
Initialization
• It means assigning the values to variable
Declaration and initialization in single
step
int a = 10;
float b = 30.05;
char c = 'a';
(Value to characters always assigned in single
quotes)
Keywords
• Are simply the reserved words whose
meaning has been explained in library of C
language.
• There are 32 keywords in c language.
• We can’t use keywords as identifiers or
variables because if we do so we are trying to
assign a new meaning to the keyword, which
is not allowed by the computer
List of Keywords
int float;
char if;
Int void;
Above will give error as we are using keywords
as identifier or variable name
Constants
• Is an identity which does not change its value.
Once the value is initialized, that can’t be
changed.
• Constants are just like variables only condition
is that their value doesn’t change.
• We will use const keyword for declaring
constants
Comments
• Comments are that part of program, which are
ignored by compiler. These are used for better
readability of user. Compiler doesn‘t compile the
text written inside comments.
• The comment describes the purpose of the code
in the file, and might include some license or
copyright information.
• It is not compulsory to have comments in our
program, but its good practice and what most C
programmers will expect to find.
Single Line Comment
// is used to make single line comment. All the
text in a line after // will become part of
comment and will be ignored by compiler.
• E.g.
int a; // this is ignored
Multiline Comment
This starts from /* and ends at */.
All the text in between these will be part of
comment.
E.g.
/* This Is
Multiline
Comment */
Rules for writing c program
• Every instruction in c program is written as separate
statement because C program is collection of statements
• There is no particular hard and fast rule for placing the
statements in our program. We can place it anywhere in
our program, that why C is known as free form language.
• Every statement will end with ; (semi-colon). So it is also
known as statement terminator.
• Proper comments and indentation should be given in c
program for better readability
• C is case sensitive language. It differs in lower and upper
case characters.
• We can‘t declare variable with same name multiple
times in single block.
Variables in C and C++ Language

Más contenido relacionado

La actualidad más candente

Data types in C language
Data types in C languageData types in C language
Data types in C language
kashyap399
 

La actualidad más candente (20)

Data types in C language
Data types in C languageData types in C language
Data types in C language
 
History of c
History of cHistory of c
History of c
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
C tokens
C tokensC tokens
C tokens
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Learn C
Learn CLearn C
Learn C
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Keywords in c language
Keywords in c languageKeywords in c language
Keywords in c language
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
c-programming
c-programmingc-programming
c-programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 

Destacado

Destacado (15)

INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
General Tips to Overcome an Interview
General Tips to Overcome an InterviewGeneral Tips to Overcome an Interview
General Tips to Overcome an Interview
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
Calculus II - 15
Calculus II - 15Calculus II - 15
Calculus II - 15
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
C data_structures
C  data_structuresC  data_structures
C data_structures
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Basics of Networks ,Advantages and Disadvantages
Basics of  Networks ,Advantages and DisadvantagesBasics of  Networks ,Advantages and Disadvantages
Basics of Networks ,Advantages and Disadvantages
 
c++ programming Unit 1 introduction to c++
c++ programming Unit 1  introduction to c++c++ programming Unit 1  introduction to c++
c++ programming Unit 1 introduction to c++
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
C language ppt
C language pptC language ppt
C language ppt
 

Similar a Variables in C and C++ Language

C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
Murali M
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 

Similar a Variables in C and C++ Language (20)

Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answer
 
lec 2.pptx
lec 2.pptxlec 2.pptx
lec 2.pptx
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
 
C language
C languageC language
C language
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
 
programming week 2.ppt
programming week 2.pptprogramming week 2.ppt
programming week 2.ppt
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variables
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
 
Uniti classnotes
Uniti classnotesUniti classnotes
Uniti classnotes
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
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
 
SPC Unit 2
SPC Unit 2SPC Unit 2
SPC Unit 2
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
C language
C languageC language
C language
 

Más de Way2itech (7)

Escape sequences
Escape sequencesEscape sequences
Escape sequences
 
Compilation of c
Compilation of cCompilation of c
Compilation of c
 
10. switch case
10. switch case10. switch case
10. switch case
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
8. operators
8. operators8. operators
8. operators
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functions
 
Introduction to c_language
Introduction to c_languageIntroduction to c_language
Introduction to c_language
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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 ...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Variables in C and C++ Language

  • 1. Variables, Datatype, Constants, Keywords, Comments, Rules for Writing C program Part 2 By: Er. Aman Kumar
  • 2. Variables • Variable is simply name given to memory location which acts as placeholder or container for storing data. It may help to think of variables as a container for a value.
  • 3. Data type • We can store variables in our computer memory. Since each type of data takes different amount of memory, like integer takes 2 bytes, decimal numbers take 4 byte, and SINGLE character takes 1 byte. So we have to tell computer about the type of data we are going to store in our variable
  • 4. • Predefined/inbuilt : These datatypes are inbuilt. eg : char, int, float, double • Drived Datatype These datatypes are inherited from predefined datatype. eg : arrays, pointer. • Userdefined datatype : These are created by user for his/her own purpose • eg : typedef, enum, structure, union
  • 5.
  • 7.
  • 8. Character set • Character set: every character is assigned unique number called character set. C/C++ follows ASCII character set. • ASCII: American standard code for information interchange • Here lowercase, uppercase characters (English), special symbols, digits have been assigned unique integer number. • Total 256 characters are there. • Range is: -128 to 127 • Here limitation is only English is used.
  • 9. Identifiers • Identifier is simply a name given to your variable, class, union, structure, function, etc. • Rules for creating valid identifiers: • 1. An identifier can be any combination of alphabets, digits, underscore. • 2. Neither spaces nor special symbol other then underscore can be used. • 3. It won‘t begin with a digit
  • 10.
  • 11. Declaration and initialization of variable • How to declare variable? • Declaration of variable means specify data type of variable and name assigned (identifier). • 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.
  • 12. • syntax : datatype varible_name; eg : int a; float b; char c; double first; int i, j, k;
  • 13. Initialization • It means assigning the values to variable
  • 14. Declaration and initialization in single step int a = 10; float b = 30.05; char c = 'a'; (Value to characters always assigned in single quotes)
  • 15. Keywords • Are simply the reserved words whose meaning has been explained in library of C language. • There are 32 keywords in c language. • We can’t use keywords as identifiers or variables because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer
  • 17. int float; char if; Int void; Above will give error as we are using keywords as identifier or variable name
  • 18. Constants • Is an identity which does not change its value. Once the value is initialized, that can’t be changed. • Constants are just like variables only condition is that their value doesn’t change. • We will use const keyword for declaring constants
  • 19. Comments • Comments are that part of program, which are ignored by compiler. These are used for better readability of user. Compiler doesn‘t compile the text written inside comments. • The comment describes the purpose of the code in the file, and might include some license or copyright information. • It is not compulsory to have comments in our program, but its good practice and what most C programmers will expect to find.
  • 20. Single Line Comment // is used to make single line comment. All the text in a line after // will become part of comment and will be ignored by compiler. • E.g. int a; // this is ignored
  • 21. Multiline Comment This starts from /* and ends at */. All the text in between these will be part of comment. E.g. /* This Is Multiline Comment */
  • 22. Rules for writing c program • Every instruction in c program is written as separate statement because C program is collection of statements • There is no particular hard and fast rule for placing the statements in our program. We can place it anywhere in our program, that why C is known as free form language. • Every statement will end with ; (semi-colon). So it is also known as statement terminator. • Proper comments and indentation should be given in c program for better readability • C is case sensitive language. It differs in lower and upper case characters. • We can‘t declare variable with same name multiple times in single block.