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 Answers
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