0% found this document useful (0 votes)
21 views

CH 3. Variables

Variables are packets that store data in programming. They must have unique names and can hold different data types like integers, floating-point numbers, characters, strings, and Boolean values. Integer variables hold whole numbers, floating-point variables hold decimal numbers, character variables hold single characters, string variables hold text, and Boolean variables hold true or false values.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

CH 3. Variables

Variables are packets that store data in programming. They must have unique names and can hold different data types like integers, floating-point numbers, characters, strings, and Boolean values. Integer variables hold whole numbers, floating-point variables hold decimal numbers, character variables hold single characters, string variables hold text, and Boolean variables hold true or false values.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

CHAPTER 3

VARIABLES
WHAT ARE VARIABLES?
In programming, variable is a packet in which
we can store data.

These packets can be named and referenced


and can be used to perform various
operations.
NAMING VARIABLES
Every variable in a program is unique. To
identify these variables uniquely, user needs to
allocate them a unique name. This name acts
as an identifier for that variable. In
programming, a user is not allowed to use the
same name of a variable more than once.
Naming variables make it to easier to call
them while performing operations. The name
of a variable also suggests what information
the variable contains.
DIFFERENT DATA TYPES IN VARIABLES
• Integer
• Floating-point number
• Character
• String
• Boolean
INTEGER DATA TYPE
• Integer data type variables store integer Example of declaring an Integer
values only. variable:
• They store whole numbers which have zero, int a = 2;
positive and negative values but not
decimal values
FLOATING POINT NUMBER DATA TYPE
Example of declaring a floating-
point number variable:
• Floating-point numbers are used to store
decimal values. They hold real numbers float a = 1.1;
with decimal values
• There is another type of floating-point
number known as a "double" data type,
which is used to store even bigger values Example of a double value:
double a = 8.999999999;
CHARACTER DATA TYPE
• Character type variables are used to store Example of declaring a character
character values variable:
• If a user tries to create a character variable
char a = ‘w’;
and assign it with a non-character value, the
program will throw an error
STRING DATA TYPE
The String data type stores value in a sequence of characters i.e. in String
format.
BOOLEAN DATA TYPE
"Boolean Data Type", which stores values in Boolean type only i.e., "true" or
"false"

Example of declaring a Boolean


variable:
bool a = true;

You might also like