Chap 09
Chap 09
SCIENCE
12
(MS Access and C)
CHAPTER 9: Elements of C
Language
Prof. Shahzeb Malik
Topics
Examples
printf scanf
2. User-defined Identifiers
Defined by the programmer.
• Used to store data and program results
Examples
my_name mark ag
s e
List of Keywords
All variables must be declared before they are used in the program otherwise
compiler
generate error
Syntax
data_type variable_name;
Examples
int marks, total; (list of variables)
double salary;
char grade;
3. String Constants
A collection of characters written in double quotations mark.
May consist of any alphabetic characters, digits and special symbols
Examples
“Pakistan “12 “99-Mall Road,
” 3” Lahore”
-215 to 215-1
216-1
precision refers
Examples the number of
10.5 5.3 -10.91 digits after the
decimal point
Types of Floating point Data Type
float
precision of 6 decimal places (least
accurate)
double
precision of 15 decimal places
long double
precision of 19 decimal places
An underflow occurs when the value assigned to a variable is less than the minimum
possible value
Example - The minimum value for int type variable is –32768. If the assigned value
is less than
-32768, then an integer underflow occurs
Arithmetic Underflow
is an error in which a very small computational result is represented as zero
e.g., 0.00000001 * 10-1000000 is equal to 0
Arithmetic Overflow
is an error in which the result is too large to be represented in a variable
Examples
Suppose we have two variables A and B where A = 10
and B = 5.
Arithmetic Expression Result
A+B 15
A–B 5
A*B 50
A/B 2
A%B 0
Syntax
Assignment operator
variable = expression;
Examples
A = 100; A constant, variable or combination of
C = A + B; operands and arithmetical operators
X=C–D+
10;
An lvalue is an operand that can be written on the left side of assignment
operator =
An rvalue is an operand that can be written on the right side of assignment
operator =
Lvalues must be variables
rvalues can be any expression
Example
distance = rate *
time; lvalue:
"distance" rvalue:
"rate * time"
All lvalues can be
used as rvalues
but all rvalues
cannot be used as
lvalues
Compound assignment operators combine assignment operator with arithmetic
operators
Syntax
Can be arithmetic operator
variable op = expression;
Example
Relational Operator