Chap 09
Chap 09
12
• Compound Condition
• Logical Operators ( AND, OR & NOT)
• Operator Precedence and Associativity of Operators
• Comments
• Type Casting ( Implicit and Explicit)
Examples
printf scanf
2. User-defined Identifiers
Defined by the programmer.
• Used to store data and program results
Examples
my_name marks age
• reserved words
• Can not be used for another purpose / can not be redefined
• Written in lowercase letters
• The total keywords is 32
List of Keywords
• no_of_students Valid.
• 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” “123” “99-Mall Road, Lahore”
-215 to 215-1
216-1
• 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.
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
• x = 5 is valid but 5 = x is not valid.
• C = A + B is valid but A+B=C is invalid.
• Compound assignment operators combine assignment operator with arithmetic operators
Syntax
Can be arithmetic operator
variable op = expression;
Example
Relational Operator