SlideShare a Scribd company logo
Chapter2
Constants, Variables,
and Data Types
2.1 Introduction
• In this chapter, we will discuss
– constants (integer, real, character,
string, enum) ,symbolic constants
– Variables (name, declare, assign)
– Fundamental data type ( int, float,
double, char, void)
Objective
• To be able to distinguish the
constants of different data type
• To be able to name, declare,
initialize and assign values to
variables
• To become familiar with fundamental
data types.
2.1 Character set
• Letters
– uppercase A…Z
– lowercase a…z
• Digits :All decimal digits 0…9
• Special characters
– Table2.1 on page23
• White spaces
2.3 C Tokens
• Keywords
• Identifiers
• Constants
• Strings
• Special symbols
• operators
2.4 Keywords and Identifiers
• Keywords
– Table2.3 on page24
– Must in lowercase
• Identifiers
– User-defined names
– Consist of letters, underscore(_), and
digits
– First character must not be digit
– Can’t use a keyword
– Can’t contain white space
2.4 Keywords and Identifiers
• Which of the following are valid
identifiers
• Max first_name n1/n2
• 3row double _34
• Boy num girl-num
2.7 Data Types
• Primary( fundamental) data types
– Integer
– Floating point ( float and double )
– Character
– Void
• Fig.2.4 on page31
2.7 Data Types
• Integer
– signed /unsigned
• int
• short int
• long int
• Floating point
– float
– double
– long double
• Character
– signed / unsigned
• void
2.7 Data Types
• Size and range of basic data types
• Table 2.7 on page31
• Table 2.8 on page32
2.5 Constants
• Integer
• Real
• Character
• String
Integer constants
• Decimal integer
– Consist of 0 through 9, +, -
• Octal integer
– Consist of 0 through 7, with a leading 0
• Hexadecimal integer
– Consist of 0 to 9, and a through f
preceded by 0x or 0X
Integer constant
• The largest integer value is machine-
dependent
• Qualifiers
– U or u: unsigned integer
– l or L: long integer
– UL or ul: unsigned long integer
– Short integer
• short is no longer than int and that
long is no shorter than int.
Integer constant
• Example2.1 Representation of integer constants on
a 16-bit computer.
#include<stdio.h>
main()
{
printf("Integer valuesnn");
printf("%d %d %dn",32767,32767+1,32767+10);
printf("n");
printf("Long integer valuesnn");
printf("%ld %ld %ldn",32767L,32767+1L,
32767+10L);
}
Real constant (double)
• (1) decimal point
– Consist of 0 through 9, . ,+ , -
– 3.14159, .94 , -.58 , +1.234
• (2)Exponential notation
mantissa e exponent
– .56e3 2.3e-3 -2.3E-3
– The exponent must be an integer number
• Suffixes f or F indicate a float constant
• L or l indicate a long double
• “Default values of constants” on page35
• Floating-Point Round-off Errors
• Take a number, add 1 to it, and
subtract the original number. What
do you get? You get 1. A floating-
point calculation, may give another
answer:
Character constant
• A character enclosed within ‘ ’
– ‘6’ ‘=‘ ‘;’ ‘ ‘
– Character constants have integer values,
For example
– ‘a’ and 97
– ‘0’ and 48
• Backslash character constants
– Table2.5 on page28
– ‘ooo’ and ‘xhh’
String constants
• a sequence of characters enclosed in
“ ”, for example
– “hello” “34” “+()” “x” “n”
• “x” and ’x’
2.6 variables
• A variable is data name that may be
used to store a data value.
– Variable names correspond to locations
in the computer's memory
– Every variable has a name, a type, a
size and a value
– Whenever a new value is placed into a
variable, it replaces (and destroys) the
previous value
– Reading variables from memory does
not change them
2.8 Declaration of variables
• The declaration of variables must be
done before they are used.
• declaration form
data-type v1,v2,…,vn;
• for example
– int count;
– float sum;
– double ratio;
– char ch;
Initialization of variables
• To initialize a variable means to
assign it a starting, or initial, value.
• In C, this can be done as part of the
declaration.
• char ch=‘ ’;
• int cows = 32,
• int dogs, cats = 94;
2.10 Assignment statement
• values can be assigned to variables
using the assignment operator = as
variable_name=value;
User-defined type declaration
• the keyword “typedef” is used to
rename an existing data type.
typedef type identifier;
• for example
– typedef int integer;
– typedef float real;
– real sum1, sum2;
– integer count;
Enumerated Types
• You can use the enumerated type to
declare symbolic names to represent
integer constants.
• declarations:
– enum spectrum {red, orange, yellow,
green, blue, violet};
– enum spectrum color;

More Related Content

What's hot

String functions in C
String functions in CString functions in C
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
C functions
C functionsC functions
Access specifier
Access specifierAccess specifier
Access specifier
zindadili
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Enums in c
Enums in cEnums in c
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
David Livingston J
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
programming9
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
MohammadSalman129
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
Nitesh Kumar Pandey
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
kashyap399
 
C pointer
C pointerC pointer
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
Sahithi Naraparaju
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari
 

What's hot (20)

String functions in C
String functions in CString functions in C
String functions in C
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
C functions
C functionsC functions
C functions
 
Access specifier
Access specifierAccess specifier
Access specifier
 
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
 
Enums in c
Enums in cEnums in c
Enums in c
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
C pointer
C pointerC pointer
C pointer
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Python list
Python listPython list
Python list
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 

Similar to Constants, Variables, and Data Types

constants
constantsconstants
constants
teach4uin
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
rohassanie
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
DivyaR219113
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf
2b75fd3051
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
ASIT
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
SINGH PROJECTS
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
ahmed abugharsa
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
FabMinds
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
Chaitanya Jambotkar
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
KauserJahan6
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
RKarthickCSEKIOT
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
Identifiers, keywords and types
Identifiers, keywords and typesIdentifiers, keywords and types
Identifiers, keywords and types
Daman Toor
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
Ease3
 
JavaVariablesTypes.pptx
JavaVariablesTypes.pptxJavaVariablesTypes.pptx
JavaVariablesTypes.pptx
charusharma165
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
Sri Harsha Pamu
 
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
dhruvjs
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
ZubairAli256321
 

Similar to Constants, Variables, and Data Types (20)

constants
constantsconstants
constants
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
 
Identifiers, keywords and types
Identifiers, keywords and typesIdentifiers, keywords and types
Identifiers, keywords and types
 
Basics of Python
Basics of PythonBasics of Python
Basics of Python
 
JavaVariablesTypes.pptx
JavaVariablesTypes.pptxJavaVariablesTypes.pptx
JavaVariablesTypes.pptx
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
 
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
1-19 CPP Slides 2022-02-28 18_22_ 05.pdf
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
 

More from Rokonuzzaman Rony

Course outline for c programming
Course outline for c  programming Course outline for c  programming
Course outline for c programming
Rokonuzzaman Rony
 
Pointer
PointerPointer
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
Rokonuzzaman Rony
 
Constructors & Destructors
Constructors  & DestructorsConstructors  & Destructors
Constructors & Destructors
Rokonuzzaman Rony
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
Rokonuzzaman Rony
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 
Humanitarian task and its importance
Humanitarian task and its importanceHumanitarian task and its importance
Humanitarian task and its importance
Rokonuzzaman Rony
 
Structure
StructureStructure
Pointers
 Pointers Pointers
Loops
LoopsLoops
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Rokonuzzaman Rony
 
Array
ArrayArray
C Programming language
C Programming languageC Programming language
C Programming language
Rokonuzzaman Rony
 
User defined functions
User defined functionsUser defined functions
User defined functions
Rokonuzzaman Rony
 
Numerical Method 2
Numerical Method 2Numerical Method 2
Numerical Method 2
Rokonuzzaman Rony
 
Numerical Method
Numerical Method Numerical Method
Numerical Method
Rokonuzzaman Rony
 
Data structures
Data structuresData structures
Data structures
Rokonuzzaman Rony
 
Data structures
Data structures Data structures
Data structures
Rokonuzzaman Rony
 
Data structures
Data structures Data structures
Data structures
Rokonuzzaman Rony
 

More from Rokonuzzaman Rony (20)

Course outline for c programming
Course outline for c  programming Course outline for c  programming
Course outline for c programming
 
Pointer
PointerPointer
Pointer
 
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
 
Constructors & Destructors
Constructors  & DestructorsConstructors  & Destructors
Constructors & Destructors
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Humanitarian task and its importance
Humanitarian task and its importanceHumanitarian task and its importance
Humanitarian task and its importance
 
Structure
StructureStructure
Structure
 
Pointers
 Pointers Pointers
Pointers
 
Loops
LoopsLoops
Loops
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Array
ArrayArray
Array
 
C Programming language
C Programming languageC Programming language
C Programming language
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Numerical Method 2
Numerical Method 2Numerical Method 2
Numerical Method 2
 
Numerical Method
Numerical Method Numerical Method
Numerical Method
 
Data structures
Data structuresData structures
Data structures
 
Data structures
Data structures Data structures
Data structures
 
Data structures
Data structures Data structures
Data structures
 

Recently uploaded

Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 

Recently uploaded (20)

Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 

Constants, Variables, and Data Types

  • 2. 2.1 Introduction • In this chapter, we will discuss – constants (integer, real, character, string, enum) ,symbolic constants – Variables (name, declare, assign) – Fundamental data type ( int, float, double, char, void)
  • 3. Objective • To be able to distinguish the constants of different data type • To be able to name, declare, initialize and assign values to variables • To become familiar with fundamental data types.
  • 4. 2.1 Character set • Letters – uppercase A…Z – lowercase a…z • Digits :All decimal digits 0…9 • Special characters – Table2.1 on page23 • White spaces
  • 5. 2.3 C Tokens • Keywords • Identifiers • Constants • Strings • Special symbols • operators
  • 6. 2.4 Keywords and Identifiers • Keywords – Table2.3 on page24 – Must in lowercase • Identifiers – User-defined names – Consist of letters, underscore(_), and digits – First character must not be digit – Can’t use a keyword – Can’t contain white space
  • 7. 2.4 Keywords and Identifiers • Which of the following are valid identifiers • Max first_name n1/n2 • 3row double _34 • Boy num girl-num
  • 8. 2.7 Data Types • Primary( fundamental) data types – Integer – Floating point ( float and double ) – Character – Void • Fig.2.4 on page31
  • 9. 2.7 Data Types • Integer – signed /unsigned • int • short int • long int • Floating point – float – double – long double • Character – signed / unsigned • void
  • 10. 2.7 Data Types • Size and range of basic data types • Table 2.7 on page31 • Table 2.8 on page32
  • 11. 2.5 Constants • Integer • Real • Character • String
  • 12. Integer constants • Decimal integer – Consist of 0 through 9, +, - • Octal integer – Consist of 0 through 7, with a leading 0 • Hexadecimal integer – Consist of 0 to 9, and a through f preceded by 0x or 0X
  • 13. Integer constant • The largest integer value is machine- dependent • Qualifiers – U or u: unsigned integer – l or L: long integer – UL or ul: unsigned long integer – Short integer
  • 14. • short is no longer than int and that long is no shorter than int.
  • 15. Integer constant • Example2.1 Representation of integer constants on a 16-bit computer. #include<stdio.h> main() { printf("Integer valuesnn"); printf("%d %d %dn",32767,32767+1,32767+10); printf("n"); printf("Long integer valuesnn"); printf("%ld %ld %ldn",32767L,32767+1L, 32767+10L); }
  • 16. Real constant (double) • (1) decimal point – Consist of 0 through 9, . ,+ , - – 3.14159, .94 , -.58 , +1.234 • (2)Exponential notation mantissa e exponent – .56e3 2.3e-3 -2.3E-3 – The exponent must be an integer number • Suffixes f or F indicate a float constant • L or l indicate a long double • “Default values of constants” on page35
  • 17. • Floating-Point Round-off Errors • Take a number, add 1 to it, and subtract the original number. What do you get? You get 1. A floating- point calculation, may give another answer:
  • 18. Character constant • A character enclosed within ‘ ’ – ‘6’ ‘=‘ ‘;’ ‘ ‘ – Character constants have integer values, For example – ‘a’ and 97 – ‘0’ and 48 • Backslash character constants – Table2.5 on page28 – ‘ooo’ and ‘xhh’
  • 19. String constants • a sequence of characters enclosed in “ ”, for example – “hello” “34” “+()” “x” “n” • “x” and ’x’
  • 20. 2.6 variables • A variable is data name that may be used to store a data value. – Variable names correspond to locations in the computer's memory – Every variable has a name, a type, a size and a value – Whenever a new value is placed into a variable, it replaces (and destroys) the previous value – Reading variables from memory does not change them
  • 21. 2.8 Declaration of variables • The declaration of variables must be done before they are used. • declaration form data-type v1,v2,…,vn; • for example – int count; – float sum; – double ratio; – char ch;
  • 22. Initialization of variables • To initialize a variable means to assign it a starting, or initial, value. • In C, this can be done as part of the declaration. • char ch=‘ ’; • int cows = 32, • int dogs, cats = 94;
  • 23. 2.10 Assignment statement • values can be assigned to variables using the assignment operator = as variable_name=value;
  • 24. User-defined type declaration • the keyword “typedef” is used to rename an existing data type. typedef type identifier; • for example – typedef int integer; – typedef float real; – real sum1, sum2; – integer count;
  • 25. Enumerated Types • You can use the enumerated type to declare symbolic names to represent integer constants. • declarations: – enum spectrum {red, orange, yellow, green, blue, violet}; – enum spectrum color;