CSCI 1730 MIDTERM STUDY GUIDE
Phases of a C program - Answer -1. edit, 2. preprocess, 3. compile, 4. link, 5. load, 6.
execute
editing phase - Answer -the program is created in the editor and stored on the disk
preprocess phase - Answer -the preprocessor program processes the code
compile phase - Answer -compiler takes the code from source files -> object code and
stores it on disk
linking phase - Answer -the linker links the object code with the libraries and creates
a.out (object code -> executable program) and stores it on disk
loading phase - Answer -the loader takes the program from the disk and puts it in
primary memory
executing phase - Answer -the CPU takes instruction and executes it, possibly storing
new data values as the program executes
preprocessor directives - Answer -#include, tell preprocessor what contents to include
when processing code
#include <stdio.h> - Answer -tells preprocessor to include the contents of <stdio.h>,
which contains input/output operations (such as printing to the screen)
printf() - Answer -prints text to screen, but to print variables within a string, you must
include format specifiers within the string, followed by the variables as subsequent
arguments to the function
%d - Answer -base 10 signed int
%u - Answer -base 10 unsigned int
%f - Answer -floating point values
%p - Answer -pointers
%x - Answer -hexadecimals
%c - Answer -characters
%s - Answer -strings
, compiling and linking - Answer -done in one step with one C source file, done
separately with multiple source files; to compile and link the source file -> pass it as
argument to gcc - generates executable file named a.out, but to specify name: gcc -o
name file.c
makefile - Answer -must be located in same directory as the C source files; cl, run, and
clean = targets - can be given to make utility as arguments, first target = default target,
either named makefile or Makefile; targets can be followed by dependencies after colon
; flags added will scrutinize source code more strictly so it follows the strict C standard
better
default target - Answer -the target that is assumed when no argument is passed to
make; the first target in the makefile
target dependencies - Answer -could be a file that needs to exist in current working
directory or another target that will be executed before executing the current target
4 basic data types - Answer -char, int, float, and double - can be combined with
modifiers signed, unsigned, short, and long
signed - Answer -leftmost bit in the binary representation is reserved for a signed bit, 0
= non-negative value represented, 1 = negative value represented
unsigned - Answer -all the bits in the binary representation are used to represent a non-
negative value
char - Answer -exactly one byte (8 bits) to store a single character - only fundamental
type with a standard size that is specified, other types it depends on compiler
implementation
sizeof() - Answer -to get number of bytes for a type, parameter = a variable
x << y - Answer -all bits in x shifted left y bits; left shift once produces a result 2 times
the original integer
x >> y - Answer -all bits in x shifted right y bits, right shift once produces a result that is
original integer divided by 2
~x - Answer -all bits in x flipped, 0->1 or vice versa
x & y - Answer -each bit in x AND each bit in y
x | y - Answer -each bit in x OR each bit in y
x ^ y - Answer -each bit in x XOR each bit in y
Phases of a C program - Answer -1. edit, 2. preprocess, 3. compile, 4. link, 5. load, 6.
execute
editing phase - Answer -the program is created in the editor and stored on the disk
preprocess phase - Answer -the preprocessor program processes the code
compile phase - Answer -compiler takes the code from source files -> object code and
stores it on disk
linking phase - Answer -the linker links the object code with the libraries and creates
a.out (object code -> executable program) and stores it on disk
loading phase - Answer -the loader takes the program from the disk and puts it in
primary memory
executing phase - Answer -the CPU takes instruction and executes it, possibly storing
new data values as the program executes
preprocessor directives - Answer -#include, tell preprocessor what contents to include
when processing code
#include <stdio.h> - Answer -tells preprocessor to include the contents of <stdio.h>,
which contains input/output operations (such as printing to the screen)
printf() - Answer -prints text to screen, but to print variables within a string, you must
include format specifiers within the string, followed by the variables as subsequent
arguments to the function
%d - Answer -base 10 signed int
%u - Answer -base 10 unsigned int
%f - Answer -floating point values
%p - Answer -pointers
%x - Answer -hexadecimals
%c - Answer -characters
%s - Answer -strings
, compiling and linking - Answer -done in one step with one C source file, done
separately with multiple source files; to compile and link the source file -> pass it as
argument to gcc - generates executable file named a.out, but to specify name: gcc -o
name file.c
makefile - Answer -must be located in same directory as the C source files; cl, run, and
clean = targets - can be given to make utility as arguments, first target = default target,
either named makefile or Makefile; targets can be followed by dependencies after colon
; flags added will scrutinize source code more strictly so it follows the strict C standard
better
default target - Answer -the target that is assumed when no argument is passed to
make; the first target in the makefile
target dependencies - Answer -could be a file that needs to exist in current working
directory or another target that will be executed before executing the current target
4 basic data types - Answer -char, int, float, and double - can be combined with
modifiers signed, unsigned, short, and long
signed - Answer -leftmost bit in the binary representation is reserved for a signed bit, 0
= non-negative value represented, 1 = negative value represented
unsigned - Answer -all the bits in the binary representation are used to represent a non-
negative value
char - Answer -exactly one byte (8 bits) to store a single character - only fundamental
type with a standard size that is specified, other types it depends on compiler
implementation
sizeof() - Answer -to get number of bytes for a type, parameter = a variable
x << y - Answer -all bits in x shifted left y bits; left shift once produces a result 2 times
the original integer
x >> y - Answer -all bits in x shifted right y bits, right shift once produces a result that is
original integer divided by 2
~x - Answer -all bits in x flipped, 0->1 or vice versa
x & y - Answer -each bit in x AND each bit in y
x | y - Answer -each bit in x OR each bit in y
x ^ y - Answer -each bit in x XOR each bit in y