C programming variables
C programming variables
Variable
A variable is the combination of a data types and an identifier (name) that
represents one or more memory locations used to hold a program's data.
1. A data type (or just simply a type) that serves two purposes:
1. Tells the compiler how to handle or manipulate the data
stored in the variable. In the example, the word float is one of
several data types we'll discuss later in this section.
2. Tells the linker how much memory to reserve to store the
contents of the variable.
2. An identifier (or name) that will be used to uniquely identify the
variable whenever we want to access or modify its contents. The
words radius and area in the example are identifiers.
Variable
Data Type
Identifier
Compiler
Linker
Memory
Int
Char
Float
2) Comprehension Questions
What are the two parts of a variable declaration?
How does the compiler use the data type of a variable?
Why is it important to reserve memory for variables?
Explain the difference between int, char, and float variables in terms
of memory usage.
Fill in the gaps with the correct terms from the text:
4) True or False
int is a data type used to represent integer values. In the MPLAB® XC16
Compiler, an int is defined as a 16-bit value, occupying two bytes of
memory.
char
char is a data type used to represent single characters. It is typically an 8-
bit value, occupying one byte of memory. In some cases, compilers with
Unicode support might define it differently.
float
float is a data type used to represent floating-point (decimal) values. It is
usually a 32-bit value, occupying four bytes of memory, and is stored using
a modified form of the IEEE-754 floating point format.
These definitions should help clarify the terms and concepts related to C
programming variables.
Answer Key for True or False
1. False
2. False
3. False
4. True
Comprehension Questions
2.The compiler uses the data type of a variable to determine how to handle or
manipulate the data stored in the variable. This includes operations that can be
performed on the data and how the data is stored in memory.
4.The difference between int, char, and float variables in terms of memory
usage is as follows:
An int variable is typically a 16-bit value in the MPLAB® XC16 Compiler, which
means it takes up one complete word (two bytes) of data memory.
A char variable is almost always an 8-bit value, taking up one byte (half of a
word) of data memory. If multiple char variables are declared, they can be
packed into the same word, with each char occupying one byte.
A float variable is usually a 32-bit value, requiring two full words (four bytes) of
data memory. The data for a float variable is encoded in a modified form of the
IEEE-754 floating point format, necessitating different handling compared to int
and char variables.