What is missing in this string initialization: char name[8] = { ‘r’, ‘a’, ‘e’, ‘t’}
Answers
Answered by
1
In my perspective a semicolon at the end is missing
Answered by
1
Correct initialization is : char name[8] = {'r','a','e','t','\0'} ;
This is the correct representation for declaring a string in C.
- For a string array representation in C, the initialization must be terminated by a null character at the end of the initialization and must be terminated by a semicolon at the end of the statement or declaration.
- Another way of declaring the array is: char name[] = {'r','a','e','t','/0'};
- This initialization declares dynamic string where the length of the string is determined automatically by the array declaration.
Similar questions