History and C basics
C Variables and I/O
OS and Memory
Pointers
Random
100

What is the editor that we use to create our C programs?

VIM

100

How do I print out int x = 5 on it's own line?

printf("%d\n", x);

100

What is the OS responsible for?

The operating system (OS) accounts for resource usage.  It is responsible for managing transactions between the hardware and programs.

100

What does a pointer store?

A pointer stores a memory address.

100

What are some optional compilation flags, and what are they responsible for?

-stc=c99: Enforces C99 standard

-Wall: Displays all warnings

-Wextra: Displays "good-advice" warnings

-pedantic: Checking conformance to coding standards

200

What are the three different categories of languages?  Hint: C is considered a high level language.

Machine Language

Assembly Language

High Level Language

200

How do I declare a constant in C?

const int NUM = 50;

200

What is buffer overflow?  Given an example of a situation where we have buffer overflow.

What string functions help us guard against buffer overflow?

Buffer overflow is when we read or write more bytes of memory then we have. 

Functions that have strn have an additional parameter "n" that provides protection against buffer overrun.  It will stop after n characters or finding the null terminator which ever comes first.  While str will stop once it finds the null terminator.

200

What is the difference between calling by value and calling by reference?

Passing by value passes the value of the variable, and any changes made to that value do not reflect back on the variable.

Passing by reference passes the address of the variable, and any changes made to the value of the variable reflects on the original variable.

200

Does the ordering of the data members of our structs matter?  Why or why not?

It does matter, different data types require different memory alignment values, doubles 8, ints and floats 4, and chars 1.  This means that they must start at an address that is divisible by that number.  We will add padding to make this happen.

300

What is a macro?

A "macro instruction" is used as a substitution. It tells the preprocessor to replace the name of the macro with the definition of the macro. Also known as a Preprocessor Macro / Directive.

300

What does 'static' do in a global context?  What does 'static' do in a local context?

In a global context static will make the variable private.  In a local context static will make the variable persistent.

300

 Give an example of the states a process can go through.

new -> ready -> running -> blocked -> ready -> running -> ready -> running -> terminated

300

What is de-referencing?

When we call our variables in such a way to get the value/contents of the variable.  For most statements such as x = x + 1 de-referencing is implicit, but for our pointers we use *.

300

List the similarities and differences between a preprocessor directive / macro and a constant.

Similarities: convention = all caps

Differences: 

Macro: #define [name] [value], not a variable, stored in Text section

constant: const [type] [name] = [value], const = modifier, variable cannot be changed, stored in Data, Stack, or Heap depending on how it's used

400

How do I compile my program "foo.c" into an executable 'foo' in one step?  How do I do it in two steps?

gcc -c foo.c
gcc -o foo foo.o

gcc -o foo foo.c

400

What is a header file?

Header files break implementation into multiple parts.  It provides a promise of a function by declaring a "prototype" of the function in the header file, as that function will be implemented elsewhere.

It also helps with reusing code.

400

Why is virtual memory important?

It allows us to use non-contiguous allocation of memory, which yields better memory utilization.

400

What are the four pointer values a pointer can have?  Which of these should we avoid?

1. Null: signifying 'Not a valid address'

2. Valid: a valid address in the current process

3. Arbitrary: an unknown address value (uninitialized state)

4. Stale: an address that was once valid but is no longer

We want to avoid arbitrary and stale because using them we can get unexpected behavior in our program, and it is hard to distinguish these from valid addresses.  To avoid these we set them to Null.


400

Is there a difference between char str[] = {'a', 'b', 'c'} and char str[] = "abc"? If so what, if not why not?

Yes, the first one is not a string but rather an array of characters.  The second one will end with the null terminator while the first one will not.

500

What are the step of our compilation process?  What order do they go in? What happens at each stage?

1. Preprocess
2. Compile
3. Assemble
4. Link

500

Write a segment of code that will take in input from a user, and print out the result.

#include <stdio.h>
int main(){
    char str[20];
    printf("Enter some text: ");
    fgets(str, 20, stdin);
    printf("%s\n", str);
    return 0;
}

500

What are the four segments of a process's memory address?  What is each segment responsible for?

Text: executable code

Data: initialized and uninitiated segments

Heap: dynamic storage allocated/de-allocated at runtime

Stack: run time support for function calls and local varaibles

500

Create a pointer, initialize it's value, and print the address and the value of the pointee.

int a = 42;
int *b = &a;
printf("%p\n", b);
printf("%d\n", *b);

500

Create a struct that has a the following data members: a char, 2 ints, and a double.

What is the size of your struct?

How can an instance of the struct be made?

How can an individual element of the struct be made?


struct myST{
    double dub;
    int i1;
    int i2;
    char ch;
}

struct myST foo = {4.21, 3, 99, 'a'};

printf("%d", foo.dub);