a. How many byte are allocated for each of the arrays? _____ char num_days[9]; _
ID: 3628378 • Letter: A
Question
a. How many byte are allocated for each of the arrays?_____ char num_days[9];
_____ signed int num_months[13];
_____ unsigned int my_dates[100] = {5, 56, 7, 9};
_____ char my_string1[10] = {‘C’, ‘P’, ‘R’, ‘E’, ‘ ‘, ‘2’, ‘8’, ‘8’};
_____ char my_string2[] = “CPRE 288”;
b. What is the value of each of the following (in decimal), using the array declarations from part a? Use “N/A” if the value is unknown.
_____ my_dates[0]
_____ my_dates[15]
_____ my_string1[3]
_____ my_string1[8]
_____ my_string2[8]
C. Explain the importance of the NULL character (i.e. ‘’ or 0) in a C-string
Explanation / Answer
a. How many byte are allocated for each of the arrays?
_____ char num_days[9]; each char is 1 byte, so 9 bytes
_____ signed int num_months[13]; each int is 4 bytes, so 52 bytes
_____ unsigned int my_dates[100] = {5, 56, 7, 9}; each int is 4 bytes, so 400 bytes
_____ char my_string1[10] = {‘C’, ‘P’, ‘R’, ‘E’, ‘ ‘, ‘2’, ‘8’, ‘8’}; each char is 1 byte, so 8 bytes
_____ char my_string2[] = “CPRE 288”; each char is 1 byte, and the string ends with a NULL character, so 9 bytes
b. What is the value of each of the following (in decimal), using the array declarations from part a? Use “N/A” if the value is unknown.
_____ my_dates[0] 5
_____ my_dates[15] 0 since its value was not specified above
_____ my_string1[3] 'E'
_____ my_string1[8] 0 since its value was not specified above
_____ my_string2[8] 0, strings are terminated by a NULL character
C. Explain the importance of the NULL character (i.e. ‘’ or 0) in a C-string
The NULL character terminates every string to indicate when the string ends, which is necessary to display it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.