Array, Strings and Structures Flashcards

1
Q

What does the address of the array point to?

A

It points to the first element of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an array name for?

A

An array name is a fixed pointer which points to the first element of the array and this cannot be altered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Are arrays passed by value or by reference?

A

Arrays are passed by reference as the name is a pointer. This means that functions can modify the same array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why do you need to pass in the size of the array into functions?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a string and an array?

A

A string is just an array of characters which has a ‘\0’ terminating character to indicate the end of the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to compare between strings?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the naming convention for structures?

A

End the name with a ‘_t’ which means type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

For structures, can you do: structure1 = structure2?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Are structures passed by value or reference into functions?

A

Passed by value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the -> operator for in structures?

A

Allows us to write (*structure).data as structure->data instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which one has higher precedence, ‘*’ or ‘.’?

A

’.’ has higher precedence so writing structure.data is not the same as (structure).data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly