Array, Strings and Structures Flashcards
What does the address of the array point to?
It points to the first element of the array.
What is an array name for?
An array name is a fixed pointer which points to the first element of the array and this cannot be altered.
Are arrays passed by value or by reference?
Arrays are passed by reference as the name is a pointer. This means that functions can modify the same array.
Why do you need to pass in the size of the array into functions?
As C does not have any access to the size of the array, you need to indicate what this size is so that when you try to access the array, it will not go over its actual size.
What is the difference between a string and an array?
A string is just an array of characters which has a ‘\0’ terminating character to indicate the end of the string.
How to compare between strings?
Use strcmp(s1, s2) and the result will be like s1 - s2. Highly recommended to use strncmp so you don’t exceed the end of the string.
What is the naming convention for structures?
End the name with a ‘_t’ which means type.
For structures, can you do: structure1 = structure2?
Yes.
Are structures passed by value or reference into functions?
Passed by value.
What is the -> operator for in structures?
Allows us to write (*structure).data as structure->data instead.
Which one has higher precedence, ‘*’ or ‘.’?
’.’ has higher precedence so writing structure.data is not the same as (structure).data