Professional Documents
Culture Documents
Introduction
Asma Majeed
1
Revision
Agenda
Variables
To be followed in today’s lecture
Simple Expressions
Keywords
Data Types
statement(s);
} End of segment
Note that
1 i nt a, b, c = 0, d = 4;
Operator Meaning
* Multiply
/ Divide Add
+ Subtract
- Modulus (return the remainder after division)
%
Note that,
multiply (*), divide (/), and modulus (%) have precedence over add (+)
and subtract (-).
parentheses, ( ), may be used to group terms.
Fundamentals of computer programming 12
Simple Expressions
Example.
1 ( 1 + 2) * 4
yields 12.
yields 12.
1 1 + 2 * 4
yields 12.
1 1 + 2 * 4
yields 9.
union
• int
• used to declare numeric program variables of integer type
• whole numbers, positive and negative
• keyword: int
int number;
number = 12;
Fundamentals of computer programming 21
Basic Data Types: IntegerTypes
22
Basic Data Types cont…
• float
• fractional parts, positive and negative
• keyword: float
float height;
height = 1.72;
• double
• used to declare floating point variable of higher precision or higher range of
numbers
• exponential numbers, positive and negative
• keyword: double
double valuebig;
valuebig = 12E-3;
Fundamentals of computer programming 23
Basic Data Types: Floating-pointTypes
24
Basic Data Types cont…
• char
• equivalent to ‘letters’ in English language
• Example of characters:
• Numeric digits: 0 - 9
• Lowercase/uppercase letters: a - z and A - Z
• Space (blank)
• Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc
• single character
• keyword: char
char my_letter; The declared character must be enclosed
my_letter = 'U'; within a single quote!
• Enumeration
enum Language {
• Values are given as a list Malay,
English,
• Example: Arabic
};
#include <stdio.h>
void main(void)
{
const double pi = 3.412;
double height, radius, base, volume;