Академический Документы
Профессиональный Документы
Культура Документы
noth/Ch6-Arrays
WHAT IS AN ARRAY
noth/Ch6-Arrays
DECLARATION OF AN ARRAY
noth/Ch6-Arrays
EXAMPLE 1
#include <iostream>
Void main ()
{
Int student_mark[5]; //declare an array called
student_mark which holds 5 integer values.
Int I;
For (i=0;i<5;i++)
{
cout<<Student[<<I,,] ;
cin>>student_mark[i]; //user is prompt for a value, and that
value is stored at the current offset which is same as the loop
counter. (0,1,2,3,4)
}
}
noth/Ch6-Arrays
EXAMPLE 2 :
noth/Ch6-Arrays
EXAMPLE 3 :
noth/Ch6-Arrays
noth/Ch6-Arrays
ARRAY INITIALIZATION
noth/Ch6-Arrays
10
noth/Ch6-Arrays
11
INCLUDE FILES
#include <cstring>
#include <cctype>
or for old compilers
#include <string.h>
#include <ctype.h>
noth/Ch6-Arrays
12
noth/Ch6-Arrays
13
Strcpy function Copies the C string pointed by source into the array pointed
by destination, including the terminating null character.
Strcat function Concatenate strings
Appends a copy of the source string to the destination string.
The terminating null character in destination is overwritten
by the first character of source, and a new null-character is
appended at the end of the new string formed by the
concatenation of both in destination.
Strlen function Get string length
Returns the length of str. The length of a C string is
determined by the terminating null-character: A C string is as
long as the amount of characters between the beginning of
the string and the terminating null character.
noth/Ch6-Arrays
14
Syntax:
int strcmp ( const char * str1, const char * str2 ); <cstring>
noth/Ch6-Arrays
15
RETURN VALUE
Returns an integral value indicating the
relationship between the strings:
A zero value indicates that both strings are
equal.
A value greater than zero indicates that the
first character that does not match has a
greater value in str1 than in str2; And a
value less than zero indicates the opposite.
noth/Ch6-Arrays
16
EXAMPLE:
OUTPUT:
Guess my favourite fruit?
Orange
Guess my favourite fruit?
Apple
Correct answer!
noth/Ch6-Arrays
17
noth/Ch6-Arrays
18