1 / 48

Null-Terminated Character Arrays

Null-Terminated Character Arrays. Character Arrays. char my_array [10];. NULL-TERMINATED. [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. . ?. ?. ?. ?. ?. ?.

pabla
Download Presentation

Null-Terminated Character Arrays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Null-Terminated Character Arrays

  2. Character Arrays char my_array[10];

  3. NULL-TERMINATED [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 ? ? ? ? ? ? char array1[10] = {‘c’,’u’,’p’}; char array2[10] = “cup”;

  4. NULL-TERMINATED [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 ? ? ? ? ? ? char array1[10] = {‘c’,’u’,’p’}; char array2[10] = “cup”;

  5. NULL-TERMINATED char name[10]; cout << “enter name: “; cin >> name; cout << name;

  6. NULL-TERMINATED [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] ? ? ? ? ? ? ? ? ? ? char name[10]; cout << “enter name: “; cin >> name; cout << name;

  7. NULL-TERMINATED [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] ? ? ? ? ? ? ? ? ? ? char name[10]; cout << “enter name: “; cin >> name; // user inputs Ahmed cout << name;

  8. NULL-TERMINATED [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? char name[10]; cout << “enter name: “; cin >> name; // user inputs Ahmed cout << name;

  9. NULL-TERMINATED [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? char name[10]; cout << “enter name: “; cin >> name; cout << name; //Ahmed is displayed

  10. NULL-TERMINATED [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] ? ? ? ? ? ? ? ? ? ? char name[10]; cout << “enter name: “; cin >> name; // user inputs Jo Ann cout << name;

  11. NULL-TERMINATED [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] J o \0 ? ? ? ? ? ? ? char name[10]; cout << “enter name: “; cin >> name; // user inputs Jo Ann cout << name;

  12. NULL-TERMINATED [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] J o \0 ? ? ? ? ? ? ? char name[10]; cout << “enter name: “; cin >> name; cout << name; //Jo is displayed

  13. Using the Null-Terminating Character [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  14. Using the Null-Terminating Character length = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  15. Using the Null-Terminating Character length = 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  16. Using the Null-Terminating Character length = 1 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  17. Using the Null-Terminating Character length = 1 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  18. Using the Null-Terminating Character length = 2 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  19. Using the Null-Terminating Character length = 2 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  20. Using the Null-Terminating Character length = 3 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  21. Using the Null-Terminating Character length = 3 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  22. Using the Null-Terminating Character length = 4 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  23. Using the Null-Terminating Character length = 4 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  24. Using the Null-Terminating Character length = 5 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  25. Using the Null-Terminating Character length = 5 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  26. Using the Null-Terminating Character length = 5 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  27. Using the Null-Terminating Character length = i= output buffer= [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  28. Using the Null-Terminating Character length = 5 i= output buffer= [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  29. Using the Null-Terminating Character length = 5 i=4 output buffer= [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  30. Using the Null-Terminating Character length = 5 i=4 output buffer=d [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  31. Using the Null-Terminating Character length = 5 i=3 output buffer=d [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  32. Using the Null-Terminating Character length = 5 i=3 output buffer=de [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  33. Using the Null-Terminating Character length = 5 i=2 output buffer=de [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  34. Using the Null-Terminating Character length = 5 i=2 output buffer=dem [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  35. Using the Null-Terminating Character length = 5 i=1 output buffer=dem [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  36. Using the Null-Terminating Character length = 5 i=1 output buffer=demh [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  37. Using the Null-Terminating Character length = 5 i=0 output buffer=demh [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  38. Using the Null-Terminating Character length = 5 i=0 output buffer=demhA [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  39. Using the Null-Terminating Character length = 5 i=-1 output buffer=demhA [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] A h m e d \0 ? ? ? ? // 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; }

  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

More Related