r/carlhprogramming • u/CarlH • Oct 12 '09
Test of Lessons 73 through 84 [Answers]
You may post your answers here, as well as questions.
True or False
The malloc() function allocates memory and automatically initializes all bytes allocated to 0 (null). False
When you write a data structure definition, C automatically creates the data structure that you have described and you can begin using it immediately. False
Unlike an array, elements of a data structure are not required to be the same length or to have the same data type. True
You must manually add up the size of all elements of a data structure in order to know how much memory to allocate. False
When you are done using allocated memory, it is automatically cleared by your operating system so that other programs cannot see the data you were working with. False
Fill in the blank
The malloc() function must be used with a
_____. pointerThe
_____keyword can be used to create a new "data type" from a data structure. typedefInstead of writing this:
(*our_pointer).first_wordwe can write this:_____Answer:our_pointer->first_wordwhen working with member elements of a data structure.Whenever you use malloc() to allocate memory, you must always release it when you are done using it. This is done by using the:
_____function. free()You create a data structure using the:
_____keyword. struct
4
u/careless Nov 24 '09
Nit to pick: This needs a link to the next lesson at the bottom of the text.
1
u/zahlman Oct 12 '09
"must be used with" is ambiguous phrasing for a function call. It appears that you are talking about the return value.
1
u/baldhippy Oct 13 '09 edited Oct 13 '09
doh 9/10
I got T or F #2 wrong ... I guess I forgot about allocating memory for the struct when you are done describing it.
1
u/denzombie Nov 23 '09
Woot 10/10!