SlideShare a Scribd company logo
Constants, Variables and Data Types
Topics
 Token, Keyword, Identifier
 Constant, Variable
 Data types
Token and Keyword
 Token- In a C program the smallest individual units
are known as C tokens. C has six types of tokens.
1. Keyword- float, int, while
2. Identifier- main, amount
3. Constant- 10.5, 10
4. String- “ABC”, “Khulna”
5. Special symbol- [ ], { }
6. Operator- +,-,*
 Keyword- Keywords are the reserve words which
have fixed meanings and that cannot be changed.
Ex- float, double, while, char, do, if, else
Identifier, Constant
 Identifier- Identifiers refer to the names of variables,
functions and arrays.
 Constant- Constants in C refer to fixed values do
not change during the execution of a program. Ex-
123, -0.75, ‘X’, “CSE”
 Process of declaring constant:
1. #define: #define const_name value
Ex: #define MAX 100
2. const: const data_type const_name = value;
Ex: const int MAX=100;
Variable
 Variable- A variable is a data name that may be
used to store data value. A variable may take
different values at different times during execution.
 Rules of variable name:
1. It must begin with a letter. Some systems permit
underscore as the first character.
2. ANSI standard recognizes a length of 31
characters. But it should normally in between 8 char.
3. Uppercase and lowercase are different.
4. Variable name should not be a keyword.
5. White space is not allowed.
Data Types
 Primary data types- character, Integer, Float,
Double
 User-defined data types- Structure, Union, Class,
Enumeration
 Derived data types- Array, Function, Pointer,
Reference
Modifier or Qualifier
 Modifier- The keyword like short, long, unsigned,
signed can change the data storage capacity of the
variable. So they are called modifier or qualifier.
 Type Size (bits) Range
char 8 -128 to 127
int or short int 16 -32768 to 32767
unsigned int 16 0 to 65535
short int 8 -128 to 127
long int 32 -2147483648 to 2147483648
float 32 3.4E-38 to 3.4E+38
double 64 1.7E-308 to 1.7E+308
long double 80 3.4E-4932 to 3.4E+4932
Variable Declaration
 Declaration does two things:
1. It tells the compiler what the variable name
is.
2. It specifies what type of data the variable
will hold.
 The declaration of variables must be done
before they are used in the program.
 Rule: Data_type Var_name;
 Ex: int x, y;
float area;
Assigning values to Variables
 Rule: var_name = constant;
Ex: balance = 1277.50;
ch = ‘Y’;
 C permits multiple assignments in one line.
Ex: length=10; height=5;
 It is also possible to assign a value to a variable at
the time of variable declaration.
Ex: int x = 100;
 C permits the initialization of more than one
variables in one statement using multiple
assignment operators.
Ex: x = y = z = 100;

More Related Content

PPTX
Variables in C++, data types in c++
PPT
3 data-types-in-c
PPT
User defined data type
PPT
Lect 9(pointers) Zaheer Abbas
PPTX
C data types, arrays and structs
PPTX
C PROGRAMMING LANGUAGE
PPTX
data types in C programming
PPTX
Variables in C++, data types in c++
3 data-types-in-c
User defined data type
Lect 9(pointers) Zaheer Abbas
C data types, arrays and structs
C PROGRAMMING LANGUAGE
data types in C programming

What's hot (20)

PPTX
Concept Of C++ Data Types
 
PPTX
Data types
PPT
C++ data types
PPTX
Concept of c data types
PPTX
Data types
PPT
Java: Primitive Data Types
PPTX
Datatype in c++ unit 3 -topic 2
PPTX
Data Types, Variables, and Constants in C# Programming
PPTX
Data types in C
PPTX
Data types in C
PPTX
Data Types and Variables In C Programming
PPTX
Data types
PPTX
Variables and data types in C++
PPTX
Data types in C language
PPTX
Basic Data Types in C++
PPTX
Structures in c language
PPTX
Introduction to c++
PDF
PPTX
Presentation on c structures
PPTX
Numerical data.
Concept Of C++ Data Types
 
Data types
C++ data types
Concept of c data types
Data types
Java: Primitive Data Types
Datatype in c++ unit 3 -topic 2
Data Types, Variables, and Constants in C# Programming
Data types in C
Data types in C
Data Types and Variables In C Programming
Data types
Variables and data types in C++
Data types in C language
Basic Data Types in C++
Structures in c language
Introduction to c++
Presentation on c structures
Numerical data.
Ad

Viewers also liked (20)

PPTX
Chapter 7.4
PPTX
Chapter 3.1
PDF
Basics in algorithms and data structure
PDF
Data Structure Basics
PPTX
Webpage Visual Design and Online Prototype
PPT
Logic Formulation 2
KEY
Calculus II - 16
PPTX
Digital Logic
KEY
Calculus II - 15
PDF
Problem Solving with Algorithms and Data Structure - Lists
PDF
Problem Solving with Algorithms and Data Structure - Graphs
PPT
Komunikasyon
PPTX
Data Structure & Algorithms | Computer Science
PPTX
ppt of VCLA
PPTX
Data structures and algorithms
PPT
មេរៀនៈ Data Structure and Algorithm in C/C++
PDF
Curves and surfaces
PPT
Earthing Concepts
PPTX
Electrical grounding and earthing
Chapter 7.4
Chapter 3.1
Basics in algorithms and data structure
Data Structure Basics
Webpage Visual Design and Online Prototype
Logic Formulation 2
Calculus II - 16
Digital Logic
Calculus II - 15
Problem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - Graphs
Komunikasyon
Data Structure & Algorithms | Computer Science
ppt of VCLA
Data structures and algorithms
មេរៀនៈ Data Structure and Algorithm in C/C++
Curves and surfaces
Earthing Concepts
Electrical grounding and earthing
Ad

Similar to Chap 2(const var-datatype) (20)

PDF
PSPC--UNIT-2.pdf
PPT
Data Handling
PDF
variablesfinal-170820055428 data type results
PDF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PPTX
Visual Basic Fundamentals
PDF
C++ PPT IN NUMERICAL METHOD FOR M.Sc PHYSICS
PPTX
Chapter 2.datatypes and operators
PDF
cassignmentii-170424105623.pdf
PPT
C language Unit 2 Slides, UPTU C language
PPT
C the basic concepts
PPTX
java Basic Programming Needs
PPT
5-Lec - Datatypes.ppt
PPTX
Module 1:Introduction
PPTX
Java chapter 2
PPT
FP 201 Unit 2 - Part 2
PPT
Introduction to c
PPTX
Unit 1 introduction to visual basic programming
PPT
Problem Solving Techniques
PPTX
PPTX
Lesson 4 Basic Programming Constructs.pptx
PSPC--UNIT-2.pdf
Data Handling
variablesfinal-170820055428 data type results
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Visual Basic Fundamentals
C++ PPT IN NUMERICAL METHOD FOR M.Sc PHYSICS
Chapter 2.datatypes and operators
cassignmentii-170424105623.pdf
C language Unit 2 Slides, UPTU C language
C the basic concepts
java Basic Programming Needs
5-Lec - Datatypes.ppt
Module 1:Introduction
Java chapter 2
FP 201 Unit 2 - Part 2
Introduction to c
Unit 1 introduction to visual basic programming
Problem Solving Techniques
Lesson 4 Basic Programming Constructs.pptx

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Business Ethics Teaching Materials for college
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Basic Mud Logging Guide for educational purpose
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Microbial diseases, their pathogenesis and prophylaxis
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharma ospi slides which help in ospi learning
Pharmacology of Heart Failure /Pharmacotherapy of CHF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Week 4 Term 3 Study Techniques revisited.pptx
Business Ethics Teaching Materials for college
STATICS OF THE RIGID BODIES Hibbelers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Cell Structure & Organelles in detailed.
Basic Mud Logging Guide for educational purpose
Module 4: Burden of Disease Tutorial Slides S2 2025
TR - Agricultural Crops Production NC III.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx

Chap 2(const var-datatype)

  • 1. Constants, Variables and Data Types Topics  Token, Keyword, Identifier  Constant, Variable  Data types
  • 2. Token and Keyword  Token- In a C program the smallest individual units are known as C tokens. C has six types of tokens. 1. Keyword- float, int, while 2. Identifier- main, amount 3. Constant- 10.5, 10 4. String- “ABC”, “Khulna” 5. Special symbol- [ ], { } 6. Operator- +,-,*  Keyword- Keywords are the reserve words which have fixed meanings and that cannot be changed. Ex- float, double, while, char, do, if, else
  • 3. Identifier, Constant  Identifier- Identifiers refer to the names of variables, functions and arrays.  Constant- Constants in C refer to fixed values do not change during the execution of a program. Ex- 123, -0.75, ‘X’, “CSE”  Process of declaring constant: 1. #define: #define const_name value Ex: #define MAX 100 2. const: const data_type const_name = value; Ex: const int MAX=100;
  • 4. Variable  Variable- A variable is a data name that may be used to store data value. A variable may take different values at different times during execution.  Rules of variable name: 1. It must begin with a letter. Some systems permit underscore as the first character. 2. ANSI standard recognizes a length of 31 characters. But it should normally in between 8 char. 3. Uppercase and lowercase are different. 4. Variable name should not be a keyword. 5. White space is not allowed.
  • 5. Data Types  Primary data types- character, Integer, Float, Double  User-defined data types- Structure, Union, Class, Enumeration  Derived data types- Array, Function, Pointer, Reference
  • 6. Modifier or Qualifier  Modifier- The keyword like short, long, unsigned, signed can change the data storage capacity of the variable. So they are called modifier or qualifier.  Type Size (bits) Range char 8 -128 to 127 int or short int 16 -32768 to 32767 unsigned int 16 0 to 65535 short int 8 -128 to 127 long int 32 -2147483648 to 2147483648 float 32 3.4E-38 to 3.4E+38 double 64 1.7E-308 to 1.7E+308 long double 80 3.4E-4932 to 3.4E+4932
  • 7. Variable Declaration  Declaration does two things: 1. It tells the compiler what the variable name is. 2. It specifies what type of data the variable will hold.  The declaration of variables must be done before they are used in the program.  Rule: Data_type Var_name;  Ex: int x, y; float area;
  • 8. Assigning values to Variables  Rule: var_name = constant; Ex: balance = 1277.50; ch = ‘Y’;  C permits multiple assignments in one line. Ex: length=10; height=5;  It is also possible to assign a value to a variable at the time of variable declaration. Ex: int x = 100;  C permits the initialization of more than one variables in one statement using multiple assignment operators. Ex: x = y = z = 100;