W6 - POINTERS Flashcards

1
Q

W6-1: What is an ADDRESS?

A

_ Every program VARIABLE occupies a UNIQUE ADDRESS in memory throughout its lifetime.

_ The ‘address of’ operator (&) applied to a variable’s identifier evaluates to the ADDRESS of that variable in memory.

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

W6-2: What is a POINTER?

A

_ A variable that holds an ADDRESS

_ To store the a variable’s address
=> define a pointer of the variable’s type and assign the variable’s address to that pointer.

A pointer takes the form: type *identifier;
1/ type * is the type of the pointer.
2/ identifier is the name of the pointer.

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

W6-3: What is the DEREFERENCING or INDIRECTION operator.

A

_ The * operator stands for ‘data at address’ or simply ‘data at’

_ This operator applied to a pointer’s identifier evaluates to the value in the address that that pointer holds.

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

W6-4: What is NULL Address?

A

_ Each pointer type has a special value called its NULL value

_ The constant NULL is an implementation defined constant that contains this null value (typically, 0).

_ This constant is defined in the and header files.

_ It is good style to initialize the value of a pointer to NULL before the address is known.

_ EX: int *p = NULL;

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

W6-5: PARAMETERS

A

A function can receive in its parameters not only DATA VALUES but also ADDRESSES of program variables.

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

W6-6: Pass by Address

A

To change the ORIGINAL values,
=> pass the ADDRESSES of their variables instead of their values.

_ Use these addresses to access the ORIGINAL values and change them from within the function.

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

W6-7: Multiple RETURN VALUES

A

_ C FUNCTION syntax only allows for the RETURN of a SINGLE value.

_ If program design requires a function that returns more than ONE value,
=> do through PARAMETER POINTERS that hold the ADDRESSES of the variables that receive the MULTIPLE return values.

_ FUNCTIONS that return values through their parameters can RESERVE their return values for reporting any ERROR codes produced by the function.

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