C Pointers Flashcards

1
Q

What is a pointer?

A

A data type that contains a memory address

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

What do we use pointers for?

A

To indirectly get to the values of variables

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

When we declare an array, is the index automatically declared?

A

No, declaring a variable doesn’t create a pointer to the variable.

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

I can manipulate the index value without changing:

A

the array value

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

I can change pointer values without affecting:

A

the memory data

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

What do the * and -> operators do?

A

They say “look in memory for” as the array name does with [] notation for arrays.

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

With pointers, how many values are we dealing with?

A

Two; the address stored by the pointer and the value at the address the pointer points.

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

What is the & operator used for?

A

To give us the memory address of a variable

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

What is * used for?

A

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

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

Where do we include *?

A

Right before the variable name in the declaration.

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

What does this do?

int *integer_pointer;

A

Declares a place to store an address and the thing that is at that address is an integer.

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

What must we assign a pointer?

A

A memory address

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

How do we get a variable’s memory address?

A

Precede it with &

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

How do we set a pointer value in C code?

A

int *integer_pointer;
int a;
integer_pointer= &a;

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

How do we read or change underlying data?

A

Precede the variable name with a *

Example:
int *integer_pointer;
int a;
int b = 20;
integer_pointer = &b; a = *integer_pointer; *integer_pointer = 10;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do we declare a pointer?

A

int *p;

void *q;

17
Q

How do we dereference a pointer?

A

int *p;

*p = 7;

18
Q

How do we assign a pointer from a regular variable?

A

int *p;
int a;
p = &a;

19
Q

What is used for a non-existent memory address?

A

A value from NULL (from sodlib.h)

20
Q

What are the two ways of declaring a function in C?

A

Include all of the code for a function before it is used

Define a prototype of the function at the top of the C file and then give the code later.

21
Q

How do we compile with multiple C files in one gcc command?

A

gcc -o executable file1.c file2.c file3.c

22
Q

How do we read in C files?

A
#include "filename.h"
Note the "" instead of
23
Q

What items are in .h files?

A
  • Constant Definitions
  • TYpe definitions
  • Function prototypes
  • # include statements for other .h files
24
Q

What are not in .h files?

A

Function implementations

25
Q

What are the five steps in the compilation process?

A
Pre-process
Compile
Assemble
Link
Load