Null-Terminated Character Arrays
Character Arrays char my_array[10];
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 ? ? ? ? ? ?
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 ? ? ? ? ? ?
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; cout << name;
NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; cout << name; [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] ? ? ? ? ? ? ? ? ? ?
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] ? ? ? ? ? ? ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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] ? ? ? ? ? ? ? ? ? ?
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 ? ? ? ? ? ? ?
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 ? ? ? ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
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 ? ? ? ?
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
Forbidden Acts char ntca[10]; ntca = “bob”; char ntca1[10] = “Bob”; char ntca2[10] = “Robert”; if (ntca1 == ntca2)
End of Session