VARIABLES
IS104 – Programming Fundamentals and Data Structures Using C
Ms. Aileen P. de Leon, MIT, MOS
VARIABLE – refers to the named area in memory that
stores a value or string assigned to that variable. It is
named storage location capable of containing a certain
type of data that can be modified during program
execution.
Ways to declare variable:
1. GLOBAL VARIABLE – outside of all functions,
including the main() function.
2. LOCAL VARIABLE – inside a function; variables
may only be used by statements that are in the
same function.
3. FORMAL PARAMETERS
DATA TYPE – this is a definition of a set of data that specifies
the possible range of a values of the set, the operations that
can be performed on the values, and the way in which the
values are stored in memory.
DATA TYPE CONTROL STRING DESCRIPTION
char %c Used for outputting letter
or symbol
char %s Used for displaying two or
more letters or symbols
and alphanumeric
int %d Used for showing whole
numbers
float %f Used for outputting
numbers with decimal
places
double %f Used for displaying larger
number with or without
decimal places
Void Valueless
OPERATOR – this is a symbol that tells the compiler to
perform specific mathematical or logical manipulations.
SYMBOL DESCRIPTION
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
div Integer division
mode Integer remainder
++/- - Increment and decrement
RELATIONAL – used to determine the relationship of one
quantity to another.
SYMBOL DESCRIPTION
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not equal to
= Used as assignment
operator
LOGICAL – used to show the ways through which these
relationships can be connected.
SYMBOL DESCRIPTION
&& And
|| Or
! Not
OTHER OPERATORS
SYMBOL DESCRIPTION
+= Plus equal
-= Minus equal
*= Multiply equal
/= Divide equal
%= Modulus equal
COMMENT – text embedded in a program for
documentation purposes. It is usually described
what the program does, who wrote it, why it was
changed, and others.
Example:
/* This program is written by Ms. Aileen P. de Leon */