Learnings of the Week - September 27, 2008
VARIABLES, CONSTANTS, OPERATORS AND EXPRESSION
IDENTIFIERS DEFINED
Identifiers are composed of a sequence of letters. Digits, and the special character _(underscore). Avoid using names that are too short or too long. Limit the identifiers from 8 to 15 characters only.
VARIABLES DEFINED
Variables are identifiers that can store a changeable value. These can be different data types.
RULES FOR DEFINING OR NAMING IDENTIFIERS
It must consist only of letters, digits, and underscore.
It should not begin with a digit.
An identifier defined in the C standard library should not be redefined.
It is case sensitive; meaning uppercase is not equal to the lowercase.
Do not include embedded blanks.
Do not use any of the C language keywords as your variable/identifier.
Do not call your variable/identifier by the same name as other functions.
VARIABLE DECLARATION
All variables must be declared before they may be used. The general form of declaration is
Type variable list;
Example: int, i, j, k;
Short i,j,k;
Note that before declaring variables, specify first the data type of the variable/s. Variables must be separated by comma. All declarations must be terminated by a semicolon (;).
The two kinds of variables are the local variables and global variables.
LOCAL VARIABLES
Variables that are declared inside a function are called local variables. It can only be referenced by statements that are inside the block in which the variables are declared.
GLOBAL VARIABLES
Global variables are known throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of any function.
CONSTANTS DEFINED
Constants are identifier/variables that can store a value that cannot be changed during program execution.
ARITHMETIC, LOGICAL, RELATIONAL, AND BITWISE OPERATIONS
Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. There are three classes of operators in C, arithmetic, logical and relational, and bitwise.
The arithmetic operators are:
Operator
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus Divisor
--
Decrement a value
++
Increment a value
RELATIONAL AND LOGICAL OPERATORS
In the term relational operator, the word relational refers to the relationship values can have with one another.
In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic.
The relational operators are:
Operators
>
Greater than
>=
Greater than or equal to
<
Less than
<=
Less than or equal to
==
Equal
!=
Not equal
BITWISE OPERATOR
Bitwise operators are the testing, setting or shifting of the actual bits in a byte or a word, which corresponds to C’s standard char and int data types and variants. Bitwise operators cannot by used on type float, double, long double, void or other more complex types.
THE ? OPERATOR
? Operator is a very powerful and convenient operator that can be used to replace certain statements of the if-then-else form.
EVALUATION EXPRESSION
Expression refers to anything that evaluates to a numeric value.
ORDER OF PREFEDENCE
Order of Precedence
( )
!, unary +,-
* . /. %
Binary + , -
<, <=, >, >=
==, !=
&&
Posted by:
RAE ANGELINE S. PALEN

