chars to represent a string. char name[] = {'C', 'h', 'a', 'r', 'l', 'e', 's'};
Not quite!'\0' at the end of a string.
char name[] = {'C', 'h', 'a', 'r', 'l', 'e', 's', '\0'};
|
char name[] = "Charles"; |
| name[0] | name[1] | name[2] | name[3] | name[4] | name[5] | name[6] | name[7] |
| C | h | a | r | l | e | s | \0 |
char name[10] = "Hi Mom!"; |
| name[0] | name[1] | name[2] | name[3] | name[4] | name[5] | name[6] | name[7] | name[8] | name[9] |
| H | i | |
M | o | m | ! | \0 | ? | ? |
#include<iostream> |
#include<iostream> |
cout a cstring, every single element before
'\0' will be printed out
#include<iostream> |
Hello! Charles |
#include<iostream> |
a
is printed).
0012FF74 |
#include<iostream> |
Amy |
chars with a null character
'\0' at the end. chars. int length(char s[]). It
returns the number of charaters of a C-string.
#include<iostream> |
The length of the string is: 12 |
while(s[index] != '\0') {
|
#include<iostream> |
Before the function call, string is |
#include<cstring>strcpy, strncpy: string copy. strcat, strncat: append one string to the other.
strlen: length of the stringstrcmp, strncmp : compare string. length function can be
rewritten as
#include<iostream> |