Week 3 Flashcards

1
Q

What are some general characteristics of C?

A

General purpose (you can code any coding task)
Compiled (turns text into binary)
Strongly typed (types cannot be manipulated).

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

What does it mean for a language to be an interpreted language?

A

Languages like Bash/Python/Node.js are interpreted.

A program called an interpreter reads your code and executes it.

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

What is a compiled language?

A

Source code is not executed by an interpreter.

Instead it is passed to a compiler which turns it into executable machine code.

The output of the compiler is an executable file which can be executed directly.

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

How do we execute a program with gcc

A

example: gcc -o executable file name source files

This looks like gcc -o prog file1.c file2.c

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

What do these gcc options do?
~~~
-Wall
-O<n>
-O1, -O2, -O3
-O0
~~~</n>

A
-Wall: generates more warnings
-O<n>: optimization level (how hard should the compiler try and make the code faster. 

-O1, -O2, -O3: increasingly aggressive. May not always produce expected results. 
-O0: disable optimizations (useful for debugging/disassembly). 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What do these options do?
-I/my/folder
-S
-l/my/library

A

-I/my/folder: search for header files in my/folder
-S: generate assembly code
-l/my/library: link dynamic library

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

What is the difference between:
~~~
int myvar;
int *myvar;
~~~

A

The first is a variable to an int val
The 2nd is a pointer to an integer

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

What happens here?
~~~
int* ptr = 0;
*ptr = 42;
~~~

A

There will be a segmentation fault

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

What is the difference between memory allocation in CPU registers and main memory?

A

CPU Registers (fast access, but only a handful of those)

Main memory (RAM) (slow, but can store lots of variables)

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

What is wrong with this line?
~~~
gcc -o myprogram.c myprogram.c
~~~

A

It passes the input file (myprogram.c) as an output file.

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

C, unlike many other languages allows you to directly access memory locations where variables are stored. What are some caveats to this?

A

Those are not physical memory locations.

Those are not absolute memory locations.

Those locations may not remain the same across executions.

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

How do we get a memory location?

A

We can store the address of a variable using &.
~~~
int* myptr = &val;
~~~

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

How are [] and * related?

A

They are both pointers. But the first guarantees that there is a 3 integer memory region allocated starting at the memory location pointed by var.

ptr is just a pointer. You can store a location in it, but there is no functional guarantee that it going to point to a useful or reasonable place in memory.

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

What do these keywords mean?

volatile
register

A

volatile: tell the compiler that a variable can change at any given time w/o being explicitly modified.

register: ask the compiler to always store a variable in a register

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

Where is a non pointer variable stored?

A

Each time you define a non pointer variable in a C program, memory is allocated for it on the stack.

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

What happens to variables once the function returns?

A

The variable will cease to exist.

17
Q

True or false, variables that are allocated on the heap must be manually allocated/deallocated.

A

True

18
Q

What is the correct format for a struct?

A
struct shape {
int height;
int width;
char name[16]
};
19
Q

What does typedef allow us to do?

A

It allows us to reference the struct without using the struct keyword.

20
Q

In this code, how many elements is in arr3?
~~~
char arr3[] = “Wassup?”
~~~

A

There are 8 because of the ‘/0’ character

21
Q
A