Professional Documents
Culture Documents
Computer Programming
(CSC425)
by
PUAN AFIZA ISMAIL
Faculty of Computer & Mathematical Sciences
UiTM MALAYSIA
2013
1
Array
Chapter 7
2
Contents
7.1 Introduction
7.2 One dimensional array
- processing one dimensional array
- accessing array components
- arrays as parameters to function
7.3 C string (character arrays)
- string comparison
- reading and writing string
For example:
float temp[5] = to store 5 float value in
temp.
int max[4] = to store 4 integer
value in max
char y[20] = to store a string
October 1, 2013 of value CSC425 : INTRODUCTION TO COMPUTER 5
PROGRAMMING
7.2
One dimensional array (cont.)
//using looping:
for(int i=0; i<5; i++)
cout << num[i];
NOTE:
If what we declare doesn’t fulfill what the size of the array wants,
for example:
int max[6]={1,2,3}
we only declare three but the array wants 6; the compiler will
assume the next three integer are zero :
“ 1,2,3,0,0,0 “
If what we declare exceeds what the array wants, for example:
int max[3]={1,2,3,4,5,6,7,8}
the array wants three but we declare 8” the compiler will only take
the first three integer :
“1,2,3”
October 1, 2013 CSC425 : INTRODUCTION TO COMPUTER 9
PROGRAMMING
7.2
One dimensional array (cont.)
List[3] = 10;
List[6] = 35;
List[5] = list[3] + list[6];
Input data
cin.get(str, m+1);