CS50 Week 5 Flashcards

1
Q

a hexadecimal memory address is prefixes with what?

A

0x

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

What is the base number for hexadecimal, and what symbols are used?

A

Base 16

0-9 and A-F

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

What does == compare for pointers?

A

The memory addresses, not the content of those addresses.

This is especially important when comparing strings.

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

How are pointers often represented in pseudocode?

A

As arrows.

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

What is the easiest way to compare strings?

A

the functions strcmp( )

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

What are two causes of segmentation faults?

A

Iterating past the bounds of an array.

Dereferencing a pointer that hasn’t been initialized.

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

What information exists in memory before it is initialized?

A

Who know!? It is just a garbage value before you put something there.

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

In what way is an array a pointer?

A

An array is a pointer with a different syntax than using a *. The two are the same thing.

  • c is equivalent to c[0]
  • (c+i) is equivalent to c[i]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Visualize a graphical representation of memory:

A
text
----------------
initialized data
------------------
uninitialized data
--------------------
       heap
          |
         V
        ^
         |
     stack
----------------------------
environmental variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the four steps of compiling?

A

pre-processing

compiling

assembling

linking

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

What happens during pre-processing?

A

The header files are pasted to the top of the program, and constants in the body are replaced with their values.

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

What happens during the compiling phase?

A

The source code is translated into assembly language.

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

What happens during assembling?

A

The assembly language is translated into machine code.

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

What happens during linking?

A

The machine code is combined with whatever other machine code has been specified.

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

What is in the “text” portion of the memory diagram?

A

The 0s and 1s of the program.

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

What is in the initialized data and uninitialized data portions of the memory diagram?

A

global variables.

17
Q

What is the danger of not checking the bounds of our arrays?

A

A stack overflow or buffer overrun attack.

18
Q

What happens when if the stack runs into the heap?

A

A segmentation fault.

19
Q

What is the tool for finding memory leaks?

A

Valgrind

20
Q

What is a memory leak?

A

Memory that has been allocated to the heap that is never freed.

21
Q

What is the command to start Valgrind

A

Valgrind ./file-name

22
Q

What is the command-line argument for a more detailed description by Valgrind?

A

–leak-check-full

23
Q

Valgrind can also detect some errors where an array is overstepped.

A

Valgrind can also detect some errors where an array is overstepped.

24
Q

What does typedef do?

A

It creates an alias for a type.

25
Q

What is a sentinel value?

A

A value that is returned when a program doesn’t work correctly.

26
Q

What is the format for sscanf()?

A

sscanf(characterArray, “Conversion specifier”, address of variables);

27
Q

What does struct do?

A

It creates a new data structure.

28
Q

What is the format for a struct?

A

struct name
{
data housed = data;
}

29
Q

How would a struct be given a new name?

A
typedef struct x
{
    data;
}
name;
30
Q

How do you access a variable inside a struct?

A

with . notation. Example?

typedef student
{
    char* name;
}
student;

student prime;
prime.name = “James”;