CS 2505 Final Exam Study Guide

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/74

encourage image

There's no tags or description

Looks like no tags are added yet.

75 Terms

1
New cards

Basic linux commands

cd - change directory

ls - list directory contents

mkdir - make directory

rmdir - remove directory (must be empty)

rm - removes file

mv - move file or rename

2
New cards

When listing files in linux, what option will show hidden files in a directory, along with the rest of the files?

-a

3
New cards

What best describes what a path is?

The roadmap from one location to another in a file system

4
New cards

What two words best describe the types of paths?

Relative and absolute

5
New cards

What symbol represents the users home directory?

~

6
New cards

What is an example of a type that is not built in to C

int32_t (as opposed to float, int, char, etc.)

7
New cards

What are the selection structures that C offers?

Switch statements and if statements

8
New cards

What are the pre-test loops in C?

While loop and for loops

9
New cards

What function allows for output in C?

fprintf or printf

10
New cards

Format flag for integers

d

11
New cards

Format flag for strings

s

12
New cards

Format flag for double

lf

13
New cards

Format flag for char

c

14
New cards

What stream is connected to the keyboard

stdin

15
New cards

What stream(s) is/are connected to the terminal or console

stderr and stdout

16
New cards

What is the first step in the compilation process

Preprocessor

17
New cards

What is the second step in the compilation process

Compiler

18
New cards

What is the third step in the compilation process

Assembler

19
New cards

What is the fourth step in the compilation process

Linker

20
New cards

What is true about the linker?

- The linker is responsible for resolving functions used in one file but created in another

- The linker creates an executable from object files (.o)

21
New cards

How do you add the debugging symbols to your executable when compiling

-g

22
New cards

True or false: All functions must be declared before they can be called

True

23
New cards

True or false: When passing a parameter to a function, by default, any changes to that parameter will always be reflected in the calling function?

False

24
New cards

When an array is passed to a function, what is the passing mechanism that is used?

pass-by-pointer

25
New cards

Rules for naming identifiers

1. Identifiers can be a combination of letters in lowercase or uppercase or digits or an underscore

2. An identifier cannot start with a digit.

3. Keywords cannot be used as identifiers.

4. We cannot use special symbols like !, @, #, $, %

etc. in our identifier.

5. Identifier can be of any length

26
New cards

What is the meaning of the scope of a variable

Where it is legal to use a variables name

27
New cards

What is the definition of the lifetime of a variable

How long the variable stays in memory

28
New cards

True or false: You can pass an array to a function and changes to that array will be communicated to the caller?

True

29
New cards

How to create a pointer

int * name;

30
New cards

Assuming you have a pointer name ptr that has not been given a target, what happens when you try to dereference it?

Most likely its a memory access violation

31
New cards

Assuming you have a pointer named ptr that has been given a target of NULL, what happens when you try to dereference it?

It will be a null pointer dereference also known as a segmentation fault

32
New cards

In a Makefile, what character must come first one the lines below the targets?

A tab

33
New cards

Parts of a Makefile

Rule, Dependency, Target

34
New cards

When running a Makefile, when does make determine to compile a file?

When the dependency is newer than the target

35
New cards

What is allowed as a rule in a Makefile?

Bash commands, linking commands, compiler commands

36
New cards

In a bash script, what must you do to it so that you can run it?

Make it executable

37
New cards

In bash, if you want to see if the last command was a success, what command will return true?

if [[ $? -eq 0 ]]; then

38
New cards

Best way to compile the files main.c and project.c into an executable named program?

gcc -Wall -Wextra -std=c11 -o program main.c project.c

39
New cards

In gdb, what command will set a breakpoint on line 32 in the file zipData.c

break zipData.c:32

40
New cards

In gdb, if you want to see the contents of a variable named var, which command will do that?

display var

41
New cards

What is the resulting output if you try to run gdb without compiling with -g

GDB will run, but trying to set a breakpoint or display variables, etc. will result in "No symbol table loaded"

42
New cards

What is a string in C

Character array

43
New cards

What do all strings end with

Null terminator character

44
New cards

strlen( )

Returns the length of a string

45
New cards

strcpy( )

Accepts two C-strings or pointers to two C-strings as arguments. The function copies the second C-string to the first C-string. The second C-string is left unchanged.

46
New cards

strcat( )

Concatenates string values and saves the result to a specified field.

47
New cards

strcmp(a, b)

Returns 0 if the strings are equal, negative if a comes before b, and positive if b comes before a

48
New cards

puts( ) and gets( )

Gets allows the user to inou stuff after the key, puts is similar to printf( ) and prints to terminal

49
New cards

What makes C strings so dangerous

Have to manually allocate and free memory, violation of the null terminator character causes issues

50
New cards

What does free( ) do

Frees the block of memory that the pointer was using, does NOT make the pointer NULL. Note that for strings and array, if the pointer is not pointing to the first location of the array, then free will not work and a segmentation fault will occur.

51
New cards

What is a memory leak

Kind of resource leak that happens when a computer software or program poorly handles memory allocations and fails to free memory that is no longer required

52
New cards

What tool is used to detect memory leak

valgrind

53
New cards

How do you use realloc( )

list = realloc(list, size*sizeof(int)) *int is whatever you want the size of, if its a list of chars use sizeof(char) etc.*

54
New cards

What is realloc used for

Resizes the memory block pointed to by the pointer that was previously allocated with a call to malloc or calloc. Returns newly allocated memory or null if the request fails.

55
New cards

How can const targets be used with pointers

Can either a.) create a pointer to a constant in C, which means that the pointer would point to a constant variable, or b.) create a constant pointer, meaning the pointer can not point to anything else

56
New cards

What is pointer casting?

When you change the type of an object to another type:

int A = 150;

Pa = &A;

double D, *Pd;

char ch, *Pc;

Can't do Pd = Pa because they don't have the same types, but we can do:

Pd = (int*)Pd;

Now we can do Pd = Pa.

Same is possible for Pc.

57
New cards

How does the size of the data type impact the range of numbers that can be represented?

Each data type has a certain amount of memory that it can hold. This means that some data types have the inabilty to store data of certain sizes. In most machines an int in 32 bits, meainging it can represent 2^32 bit patterns (4,294,967,296). This means if the int is unsigned it can be any int from 0 to 4,294,967,296, if it is signed then we "split" it, meaning the variable can store -2,147,483,648 --> +2,147,483,648.

58
New cards

How are negative integers stored in a computer?

Using two's complement

59
New cards

What is big endian? What affect does it have on data?

It indicates that the larger bytes (most significant value) are represented first from left to right. For example, the two bytes required to store hexadecimal number 4F52 would be stored as 4F52, with 4F being at storage location N and 52 being at the location N+1

60
New cards

What is little endian? What affect does it have on data?

Similar to big endian, it indicates that the smaller bytes are represented on the left and the biggest ones are on the right. The two bytes required to store the number 4F52 would be represented as 524F, with 52 being at location N and 4F being at N+1

61
New cards

What are the bitwise operators in C?

& - Binary AND operator copies a bit to the result if it exists in both operands (defaults to zero if not true for both)| - Binary OR operator copies a bit if it exists in either operand (referring to the ones, if there are no ones then it is a 0)^ - Binary exclusive OR, copies the bit if it is set in one of but not both operands (Again, only true for the ones)~ - Binary Ones Complement Operator is unary and has the effect of flipping bits<< - Binary left shift operator. The left operands value is moved left by the number of bits specified by the right operand>> - Binary right shift operator. The left operands value is moved right by the number of bits specified by the right operand.

62
New cards

What happens when you shift a signed integer to the right? To the left?

When shifting to the right, it is the equivalent of dividing the number by 2^N (throwing out remainders) where N is the number of bits shifted.

Ex.) 11010010 >> 2 = 00110100

210/(2^2) = 52

Shifting to the left is the opposite, and is therefore equivalent to multiplying the decimal number by 2^N

Ex.) 0010 << 2 = 1000

2 * (2^2) = 8

63
New cards

Big ended vs little ended

In a big-endian system, the most significant byte (i.e. the byte containing the highest order bits) is stored at the lowest memory address, while the least significant is stored at the higest memory address.In a little-endian system we see the opposite, where the least significant is stored at the lowest memory and the most significant is stored at the highest memory.

Pros/Cons:

Little endian is less intuitive while reading, but it also means that when new data is added you don't need to shift everything over in order to add, you can just add the data to the end. For big-endian, it is more intuitive to read left to right, but you need to shift everything down in order to add more data to the front.

Ex.) For hexadecimal number 0X1234

Big-endian:

Address: Contents:

0X0000 0X12

0X0001 0X34

Little-endian:

Address: Contents:

0X0000 0X34

0X0001 0X12

64
New cards

Setting or unsetting bits

To set a bit you would use the OR bitwise operator, and to unset a bit you would use the AND operator

Ex.)

Setting:

x |= (1<

65
New cards

Accessing fields of a struct

If you have a struct variable, you can access by doing:

struct.field

If you have a pointer to a struct, you have to access by doing:

struct->field

66
New cards

What are the 32-bit registers?

Same as 16 bit registers, but have more space (32 bits as opposed to 32) and are denoted by an E in front of the name (EAX, EBX, ESI, EBP, etc.). EFLAGS is also an example of a 32 bit register, contains status flags.

67
New cards

What are the 64-bit registers?

Same as 16 bit and 32 bit registers, but are denoted by an R in front of the name (RAX, RBX, RSI, RBP, RFLAGS, etc.). Note the size difference as well.

68
New cards

What do the single letter suffixes on our commands mean?

They indicate the size of the data being manipulated:

b = byte (8 bits)

w = word (16 bits)

l = longword (32 bits)

q = quadword (64 bits)

t = ten bytes (80 bits)

69
New cards

What is the %rsp? %rbp?

%rsp is a register that holds the address of the current position of the stack pointer. The stack pointer is a special register that keeps track of the current top of the stack, which stores temporary data during function calls and other operations. %rbp is a register that holds the address of the current position of the base pointer. It is a reference point for accessing data on the stack, particularly local variavles in a function.

70
New cards

What direction does the stack grow in?

It grows towards lower addresses, the top element has the lowest address and vice versa. It grows "downwards" as more stuff is added

71
New cards

What does the call function do that is "hidden" in the call command?

The call instruction automatically handles pushing the return address onto the stack and setting the IP to the called function's address, making it easier to call function from higer-level languages

72
New cards

What happens when a function is entered? What happens to the base pointer? What happens to the stack pointer? How many bytes are in the stack frame?

When a function is entered, the current value of the base pointer (BP or RBP) is pushed onto the stack to create a stack frame. Then the stack pointer (SP or RSP) is moved down by the amount of space needed for local variables and other function call information, such as the return address. The new value of the base pointer is then set to the current value of the stack pointer, which establishes a fixed reference point for accessing local variables and parameters.The amount of space allocated for the stack frame depends on the number and type of local variables and the amount of space required for the function call information. The total size of the stack frame is usually a multiple of the word size of the processor (e.g., 4 bytes on a 32-bit processor, 8 bytes on a 64-bit processor).When the function returns, the stack pointer is restored to its original value, the base pointer is popped off the stack, and control is transferred back to the calling function.

73
New cards

What registers are used for passing parameters? If all of those are used, where do the extra parameters go?

1: %rdi

2: %rsi

3: %rdx

4: %rcx

5: %r8

6: %r9

If there are more than 6 arguments, the additional arguments are passed on the stack in reverse order (right to left) before the function is called. The caller is responsible for pushing the arguments onto the stack and for clearing them up after the function is returned.

74
New cards

What is the general formula for computing an address

0xbase address + (index scale fator) + displacement

75
New cards

What is leaq? How is it used?

It is used to load the effective address of a memory operand into a register. It effectively makes a pointer.