CSE13S Lecture 8 & 9

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

GDB

GNU Project Debugger, a command-line tool used to debug programs by controlling their execution and inspecting their state

2
New cards

cc –g hello.c –o hello

Add the –g option with the cc command to enable debugging

3
New cards

Two debugging tools

GNU Debugger (gdb) – for logical errors

○ Valgrind – for memory errors

4
New cards

Starting up gdb

Simply run gdb passing the executable in the argument

○ Example: gdb ./hello

The GNU Debugger (gdb)

5
New cards

What can you do with gdb?

knowt flashcard image
6
New cards

What is an array?

The size may be determined either at compile time (static memory allocation) or at run

time (dynamic memory allocation).

<p>The size may be determined either at compile time (static memory allocation) or at run</p><p>time (dynamic memory allocation).</p>
7
New cards

Static arrays:

declared using static memory allocation technique

○ Size is fixed and specified in the code

○ Memory is allocated at compile time on the

function stack frame

<p>declared using static memory allocation technique</p><p>○ Size is fixed and specified in the code</p><p>○ Memory is allocated at compile time on the</p><p>function stack frame</p>
8
New cards

Dynamic arrays:

declared using dynamic

memory allocation technique

○ Size is specified at run-time

○ Memory is allocated at run time from the heap

○ Memory allocated using functions such as

malloc, calloc and realloc from the stdlib.h file

<p>declared using dynamic</p><p>memory allocation technique</p><p>○ Size is specified at run-time</p><p>○ Memory is allocated at run time from the heap</p><p>○ Memory allocated using functions such as</p><p>malloc, calloc and realloc from the stdlib.h file</p>
9
New cards

Array initialization:

type array-name[size] = {list of values};

10
New cards

Summary of scope and lifetime of variables

<p></p>
11
New cards

Macros for functions

Example: #define MIN(x, y) ((x) < (y) ? (x) : (y))

 Example: #define MAX(x, y) ((x) > (y) ? (x) : (y))

(condition) ? (expression_if_true) : (expression_if_false)

So it works like:

If condition is true → result = expression_if_true

If condition is false → result = expression_if_false

12
New cards

Passing 2-D arrays to functions

Function must be called by passing only the array name

○ Function declaration and definition must indicate that the array has 2 dimensions by including

2 sets of brackets

○ The size of the second dimension must be specified