Module 10: Variables & Pointers Flashcards

1
Q

type modifiers

A

change the width of data types

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

name of an array

A

acts as the starting address where the array is stored in memory; the equivalent of an assembly label

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

casting

A

allows programmer to forcibly convert one data type to another

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

typedef

A

allows you to give known type a new name

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

pointer

A

variable that can only contain the memory address of another variable

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

dereference

A

the act of looking up the value that the pointer points to

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

the “address operator” in C. if it precedes any variable, it will determine its runtime address

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

void

A

officially a data type but really more of a keyword to indicate the absence of data

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

void* pointer

A

a typeless pointer, so it can point to any type of data. one limitation is that it cannot be dereferenced; you would have to cast it to a typed pointer in order to dereference it. the void* pointer’s purpose is to allow for the passage of a memory address but not to allow dereferencing

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

implicit cast

A

smaller to bigger conversions are implicit; compiler does this for you

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

explicit cast

A

bigger to smaller conversions you must do explicitly
int a = 5 ;
float b = 5.0 ;
a = (int) b ;

note that the b is truncated, fraction is lost, no rounding

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

why do we need pointers in C?

A
  1. helps us to pass addresses to functions instead of data
  2. recall that in C we pass copies of local variables to functions in order to ensure their local scope is protected
  3. pointers allow us to break scope and send address of a local variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

pointers vs. arrays

A

name of array: a label for an address in data memory that contains data

pointer: a variable that contains a memory address of a variable that contains data

you cannot change the address of an array (it is a label!)

you can change the address held onto by a pointer

you can use the [ ] operator as a dereferencing operator on a pointer

  • helpful if pointer points to an array
  • don’t let that confuse you into thinking that a pointer is an array!

you can do pointer arithmetic on a pointer but NOT on an array!

passing the name of an array is the same as passing a memory address

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

intitializing pointers

A

ALWAYS initialize! this will help to avoid unexpected behavior in your program.

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

constant in C

A
#define - you can change the next time you compile
#define statements are like assembly directives (no space allocation)

const types - constants that never change
space allocation!

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

CONST applied to pointers

A

pointer to a constant:
we CAN change what the pointer points to but not the value of what it points to

constant pointer to a variable:
we can’t change what pointer points to but we can change the value of what it points to

constant pointer to a constant variable:
we can’t change what pointer points to
we can’t change the value of what it points to

17
Q

3 basic regions of data memory in C

A
  1. stack (local variables, arguments, returns)
  2. global/static region (global vars, static vars)
  3. heap (dynamic space)
18
Q

2 basic storage classes

A

automatic variables: lose their values when their block terminates (since they are on the stack)
-arguments, return types, local variables

static variables: retain values between invocations
-global variables are a type of static variable