0% found this document useful (0 votes)
39 views14 pages

C3 - Variables

Variables are names that refer to memory locations that hold values. Variables can change values and are placeholders for data. Constants cannot change values and are used to represent non-changing values like PI. Variables and constants must follow naming conventions and have initialized values and data types that determine their storage and usage.

Uploaded by

gracia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views14 pages

C3 - Variables

Variables are names that refer to memory locations that hold values. Variables can change values and are placeholders for data. Constants cannot change values and are used to represent non-changing values like PI. Variables and constants must follow naming conventions and have initialized values and data types that determine their storage and usage.

Uploaded by

gracia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Variables

• Variables are simply names used to refer to some


location in memory – a location that holds a value with
which we are working.
• Variables are placeholder for a value.
• Variable can hold different value at different instance.
Rules for naming variables:
• All variable names must begin with a letter of the alphabet
or an underscore( _ ). ...
• After the first initial letter, variable names can also contain
letters and numbers. ...
• Uppercase characters are distinct from lowercase
characters.
• We cannot use a C keyword (reserved word) as a variable
name.
Variable Initialization
• Initialization is the assignment of an initial
value for a data or variable.
• Initialization is performed depends on
programming language, as well as data type,
storage class, etc.
Example variable:
Sum, Avg, avg, _date,S_No etc.
Constants/Literals
• A constant is a value (or an identifier) whose
value cannot be altered in a program. For
example: 1, 2.5, 'c' etc.
• Here, 1, 2.5 and 'c'are literal constants. Why? You
cannot assign different values to these terms.
• You can also create non-modifiable variables in C
programming. For example:
• const double PI = 3.14; Notice, we have added
keyword const.
Constant Example
• Here, PI is a symbolic constant. It's actually a
variable however, it's value cannot be
changed.
const double PI = 3.14;
PI = 2.9; //Error
• Here, PI is a symbolic constant. It's actually a
variable however, it's value cannot be
changed.
• const double PI = 3.14; PI = 2.9; //Error
Types of C Constant
• Integer constants
• Real or Floating point constants
• Octal & Hexadecimal constants
• Character constants
• String constants
• Backslash character constants
Data types
• C data types are defined as the data storage format that a
variable can store a data to perform a specific operation.
• Data types are used to define a variable before to use in a
program.
• Size of variable, constant and array are determined by data
types.
• Types of Data types,

You might also like