Download presentation
Presentation is loading. Please wait.
1
Null-Terminated Character Arrays
2
Character Arrays char my_array[10];
3
NULL-TERMINATED char array1[10] = {‘c’,’u’,’p’}; char array2[10] = “cup”; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] c u p ? ? ? ? ? ? ? [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] c u p \0 ? ? ? ? ? ?
4
NULL-TERMINATED char array1[10] = {‘c’,’u’,’p’}; char array2[10] = “cup”; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] c u p ? ? ? ? ? ? ? [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] c u p \0 ? ? ? ? ? ?
5
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; cout << name;
6
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; cout << name; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] ? ? ? ? ? ? ? ? ? ?
7
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; // user inputs Ahmed cout << name; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] ? ? ? ? ? ? ? ? ? ?
8
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; // user inputs Ahmed cout << name; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
9
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; cout << name; //Ahmed is displayed [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
10
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; // user inputs Jo Ann cout << name; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] ? ? ? ? ? ? ? ? ? ?
11
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; // user inputs Jo Ann cout << name; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] J o \0 ? ? ? ? ? ? ?
12
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; cout << name; //Jo is displayed [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] J o \0 ? ? ? ? ? ? ?
13
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
14
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
15
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
16
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 1 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
17
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 1 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
18
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 2 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
19
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 2 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
20
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 3 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
21
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 3 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
22
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 4 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
23
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 4 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
24
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 5 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
25
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 5 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
26
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. long string_length (const char ntca[]) { long length = 0; while (ntca[length] != ‘\0’) length++; return length; } length = 5 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
27
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = i= output buffer= [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
28
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i= output buffer= [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
29
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=4 output buffer= [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
30
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=4 output buffer=d [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
31
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=3 output buffer=d [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
32
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=3 output buffer=de [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
33
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=2 output buffer=de [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
34
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=2 output buffer=dem [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
35
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=1 output buffer=dem [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
36
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=1 output buffer=demh [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
37
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=0 output buffer=demh [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
38
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=0 output buffer=demhA [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
39
Using the Null-Terminating Character
// Pre: char array must have null character at the end of data. void print_reverse (const char ntca[]) { long length = string_length(ntca); for (long i = length-1; i >= 0; i--) cout<<ntca[i]; return; } length = 5 i=-1 output buffer=demhA [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ?
40
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
41
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
42
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
43
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
44
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
45
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
46
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
47
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
48
End of Session
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.