+ 1
C++ Error
Can someone help? The following code outputs an error and I'm not sure how to fix it. char arr [1] = {}; arr [0] = char "A";
7 Antworten
+ 4
Char is ' ' not " ".
And, I’m not sure, but a char is not an array, because there’s only one character
+ 5
Because "A" is a char array with two elements and 'A' is a single char.
char name[] = "Zack";
and
char name[] = {'Z', 'a', 'c', 'k', '\0'}
are the same 5 character arrays.
+ 5
Because that character is used to terminate "strings". Otherwise, they would never end and would print all of memory.
+ 5
char x[] = "Zack";
while (*x != '\0') {
cout << *x;
x++;
}
is identical in concept to:
char x[] = "Zack";
cout << x;
The second is faster as the loop is within the function cout uses instead of multiple calls to the function.
+ 3
Why '\0' at the end ?
+ 3
Ok thanks
+ 1
yes it was ' '. I also had to remove the second "char" for it to work. But why should ' ' and " " be different?