C Pointers Flashcards

1
Q

What is a pointer?

A

A pointer is a data type that contains a memory location

We can use a pointer to indirectly get to the values of variables.

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

When we say pointers have two values, what values are we referring to?

A

The address to stored by the pointer

The value at the address where the pointer points

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

What is the ‘&’ pointer operator?

A

Used to give the memory address of a variable

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

What is the ‘*’ pointer operator?

A

Used to tell us to look through the pointer to the underlying data

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

Does a pointer declaration creates space for the data?

A

NO!!!

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

What is ‘pass by reference’

A

Declare a function parameter to be a pointer to the variable in the calling function.

foo( int *a ) {
a = 10; / Sets the variable in the caller to 10 */
}

main() {
int b;
foo( &b ); /* b returns with the value 10 */ }

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

Basic Pointers

A

Declaration
int *p;
void *q;

Dereferencing
int *p;
*p = 7;

Assigning to a pointer from a regular variable int *p;
int a;
p = &a;

A value of NULL (from stdlib.h) is used for a non-existent memory address

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