0

ASCII ' \\ ' in a char array [unresolved]

char arr[4] = {'|', '\\', '/'}; for (int a = 0; a<4; a++) cout << arr[a]; Question 1: What is the fourth element? Is it like an int array in that unspecified elements will be set to 0? Or is it nothing (space)? Or is it something random? Question 2: Is the second element \\ considered one char or two? If we want to output \\ instead of \ would we need to use char* instead? Question 3: What is cout << arr[a];

29th Jul 2020, 6:07 AM
Solus
Solus - avatar
2 odpowiedzi
0
For char arrays, the default value is '\0'. For array of pointers, the default value is nullptr. For strings, the default value is an empty string "". '\\' is a character constant representing a single character. Its called Multicharacter literal and has type int and implementation-defined value. Output for cout<<arr[a]; | \\ / \0 a will take values from 0 to 3 after iteration.
29th Jul 2020, 7:44 AM
123
0
Aksita G Apparently the correct output is |\/ Still need help for this question.
29th Jul 2020, 7:00 PM
Solus
Solus - avatar