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

What is the name of a common program maintenance utility on Unix-based systems?

make

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 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

C is considered an imperative programming language.  What does it mean to have be an imperative programming language?

A programing paradigm that describes computation in terms of statements that change a program state.

300

Which function would be used to convert a C string to a number?

strtol()

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

What does static do in a local context?

What does static do in a global context?

Locally static makes the value of the variable persistent through several calls of the function.

Globally static makes the variable private (internally linked)


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 is the meaning of a pointer that is declared as 'const'?

The value to which the pointer points is constant.

400

Is there a difference between char str[] = {'a', 'b', 'c'} and char str[] = "abc"?

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 steps of the compilation process?  What order do they go in?

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 segments of a program's memory?  What is each segment responsible for?

Text: executable code

Data: initialized variables

BSS: uninitialized variables

Heap: dynamic storage allocated/de-allocated at runtime

Stack: memory of function calls

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);