Professional Documents
Culture Documents
BFF/ BHM 2003 Computer Programming
BFF/ BHM 2003 Computer Programming
May 6, 2021
BY END OF THIS CLASS, YOU SHOULD BE ABLE
TO:
BFF2003: LECTURE 3
Use and construct various variable types and constant
declarations for all sizes of numeric data and strings.
2
IDENTIFIERS
allow us to name data & other objects in the program.
May 6, 2021
Each identified object in the computer is stored at a
BFF2003: LECTURE 3
unique address.
3
May 6, 2021 BFF2003: LECTURE 3
4
IDENTIFIERS
IDENTIFIERS
The C language contains 37 keywords:
May 6, 2021
Auto extern short
_Bool float signed
BFF2003: LECTURE 3
break for sizeof
case goto static
char if struct
_Complex _Imaginary switch
const inline typedef
continue int union
default long unsigned
do register void
double restrict volatile
else return while 5
enum
IDENTIFIERS
Themacros and C++ keywords also should be treated as
May 6, 2021
keywords:
BFF2003: LECTURE 3
and compl or
and_eq complex OR_EQ
bitand imaginary struct
bitor not xor_eq
bool not_eq
6
IDENTIFIERS
Good identifier names are descriptive but short
May 6, 2021
(including use abbreviations).
student stdnt
BFF2003: LECTURE 3
C allows name to be up to 63 characters long (if longer
than that, only the first 63 used)
BOSTON: Pegawai pentadbiran kerajaan 'dengan malu' terpaksa mengaku papan tanda nama Tasik
Chargoggagoggmanchauggagoggchaubunagungamaugg di Massachusetts, nama paling
panjang bagi sebuah tasik di wilayah itu, tersilap eja sejak bertahun-tahun lamanya.
Kesilapan ejaan nama tasik mengandungi 45 huruf itu didedahkan akhbar tempatan Worcester Telegram & Gazette yang sudah
mengesan kesilapan ejaan berkenaan sejak 2003.
May 6, 2021
BFF2003: LECTURE 3
Note
An identifier must start with a letter or underscore:
it may not have a space or a hyphen.
C is a case-sensitive language.
May 6, 2021
BFF2003: LECTURE 3
Divide into 4:
12
TYPES: VOID TYPE
Designated by keyword void
May 6, 2021
Has no value and no operations but very useful data type.
BFF2003: LECTURE 3
E.g.use to designate that a function has no parameters as
in the main function.
13
TYPES: INTEGRAL TYPE
Has3 integral types:
May 6, 2021
Boolean
Character
BFF2003: LECTURE 3
Integer
Integral
types cannot contain a fraction part; they are
whole numbers.
14
TYPES: BOOLEAN TYPE
Represent only two values: true false
May 6, 2021
C used integers to represent the Boolean value:
BFF2003: LECTURE 3
A nonzero number (+ve or –ve) true
A zero numberfalse
15
TYPES: CHARACTER TYPE
Evenwe think of characters as the letters of the alphabet,
a computer has another definition.
May 6, 2021
BFF2003: LECTURE 3
A character any value that can be represented in the
computer’s alphabet or character set.
16
TYPES: CHARACTER TYPE
Most computer use the American Standard Code for
Information Interchange (ASCII) alphabet.
May 6, 2021
BFF2003: LECTURE 3
You do not need to memorize this alphabet but you will
learn many of the special value by using them. (ASCII
code included in Appendix A).
May 6, 2021
are characters for compose words and sentences.
BFF2003: LECTURE 3
What make the letter a different from the letter x?
May 6, 2021
C defines these data types so that they can be organized
BFF2003: LECTURE 3
from the smallest to the largest & the size of the field in
which data can be stored.
sizeof (short) ≤ sizeof (int) ≤ sizeof (long) ≤ sizeof (long long)
22
TYPES: INTEGER TYPE
Each integer size can be a signed or an unsigned integer.
May 6, 2021
For signed= one bit for a signed (0 is + ; 1 is - ).
BFF2003: LECTURE 3
Forunsigned = a positive number is 2X as large as the
signed integer of the same size.
23
TYPES: INTEGER TYPE
May 6, 2021
Typical integer size and values for signed integers
BFF2003: LECTURE 3
24
TYPES: FLOATING-POINT
TYPES
TheC standard recognize three:
May 6, 2021
Real
Imaginary
BFF2003: LECTURE 3
Complex
May 6, 2021
BFF2003: LECTURE 3
Support 3 different size of real types.
Note
sizeof (float) ≤ sizeof (double) ≤ sizeof (long double)
26
TYPES: IMAGINARY TYPES
Is used extensively in maths and eng.
May 6, 2021
Like real number multiplied by 1
BFF2003: LECTURE 3
Have three different size:
float imaginary
double imaginary
May 6, 2021
Combination of a real number and imaginary number.
BFF2003: LECTURE 3
Have a different sizes as real or imaginary types.
28
May 6, 2021 BFF2003: LECTURE 3
29
TYPES
VARIABLES
Are named memory location that have a types, such as
integer or character, which is inherited from their type.
May 6, 2021
BFF2003: LECTURE 3
The type determines the values that a variable may
contain the operations that may be used with its values.
30
VARIABLES DECLARATION
Each variable in your program must be declared and
defined at the same time (but have some exception later)
May 6, 2021
…
BFF2003: LECTURE 3
A declaration is used to name an object.
31
May 6, 2021 BFF2003: LECTURE 3
32
VARIABLES
May 6, 2021 BFF2003: LECTURE 3
33
VARIABLES
VARIABLES INITIALIZATION
We can initialize a variable at the same time we declare it
by including an initializer.
May 6, 2021
BFF2003: LECTURE 3
The initializer establishes the 1st value that the variable
will contain.
34
May 6, 2021 BFF2003: LECTURE 3
VARIABLES INITIALIZATION
35
VARIABLES INITIALIZATION
May 6, 2021
BFF2003: LECTURE 3
Note
When a variable is defined, it is not initialized.
We must initialize any variable requiring
prescribed data when the function starts.
36
May 6, 2021 BFF2003: LECTURE 3
VARIABLES INITIALIZATION
37
May 6, 2021 BFF2003: LECTURE 3
VARIABLES INITIALIZATION
38
May 6, 2021 BFF2003: LECTURE 3
VARIABLES INITIALIZATION
39
END OF TODAY’S LECTURE
Thank you for your attention.
May 6, 2021
BFF2003: LECTURE 3
Now, we were move to the practical work
(the important part of this class).