CS50 Week 1 Shorts Flashcards
Who were boolean values named after?
George Boole
What are the two possible conditions of a boolean value?
True and False
What are the boolean operators in C?
And &&
Or ||
Not !
what are the possible permutations of an AND expression?
TRUE and TRUE = TRUE
TRUE and FALSE = FALSE
FALSE and TRUE = FALSE
FALSE and FALSE = FALSE
What are the possible permutations of an OR expression?
TRUE and TRUE = TRUE
TRUE and FALSE = TRUE
FALSE and TRUE = TRUE
FALSE and FALSE = FALSE
What doe the NOT operator do?
It takes a boolean operator and returns the opposite of it.
What are the numerical representations of TRUE and FALSE in C?
0 = FALSE
Everything else = TRUE
What are the four major steps of the clang compiler?
1) Pre-processing, done by the pre-processor.
2) Compiling, done by the compiler.
3) Assembly, done by the assembler.
3) Linking, done by the linker.
What does the pre-processor do?
It recognizes pre-processor directives like #include and #define.
Libraries that are #included are appended to the top of the source code.
Constants that are #defined are replaced with their respective values.
What is the clang command to only run the pre-processor?
-E
What is the clang command to send your output to a new file?
> filename.c
What is done during the compiling portion of the compilation process?
The source code is converted to assembly code.
This is called compiling into assembly code.
What is the clang command to only run through the compilation step?
-S
What happens during the assembly portion of compilation?
The assembly code is converted into “object code,” or “machine code”.
What is machine code?
The actual 1’s and 0’s that the computer can read.
Why is the same source code compiled into different assembly code on different computers?
The assembly code is processor specific.
What is the clang command to only go through the assembly phase of compilation?
-c
What happens during the linking phase of the compilation process?
The linker combines together object code from different files into one file.
Why is it a good idea to run clang on every file?
Because linking can be very system specific.
What must be contained in at least one of the object files?
a main() function.
What is the clang command to link a file into the finished file?
- l + the file name.
- lname
Where do -l arguments go?
The end of the clang command.
Where do -l arguments go?
The end of the clang command.
What are three other terms for functions?
procedures, sub-routines, and sub-programs
What is the term for the organizational benefit of functions?
encapsulation
What are the inputs to a function called?
Arguments, or parameters.
Must a function take an argument, or return something?
No to both
What is the term for the declaration of a function?
The prototype
What is the return type for a function that returns nothing?
void
What is a side effect?
When a function has an effect other than its return value.
What is the return type of main()?
int
What are the arguments allowed for main()?
int argc
char* argv[]
What does argc contain?
The number of command line arguments passed into the program.
What does char* argv[] contain?
The string representations of the command line arguments passed.
In general, what is a library?
a collection of related, prewritten code.
What kind of files does a library consist of?
A library is a binary file that has been produced by linking together a collection of object files using a linker.
What two kinds of files do libraries typically consist of?
header files and implementation files.
What is the file extension for a header file?
.h
What does a header file describe?
The resources available in the library. This can include: functions variables structs type definitions etc.
What is a common term for the resources described in a header file?
The interface.
Why are there no function definitions in the header file?
Information hiding, or encapsulation. It protects the user from changes in implementation.
What is the file extension for the implementation file?
.c
What does the binary library file consist of?
The header and implementation files, after they have been compiled and linked together.
What will the library writer ship?
The header file and the binary file.
What two things are needed to use a library?
include the header file above main()
Link the binary file during compilation.
What are the two syntaxes used to include a header file?
include if the header file is in the default include library, which is typically usr/include.
What is make?
A program that organizes invocations of commands to the compiler, ensuring that things are compiled in the proper order and in the proper way.
What is the make command to compile a file?
make file
What is the default output for clang?
a.out
At the most basic level, what is the command to run clang on a file?
clang file.c
What is the clang command to control what the name of the output is?
-o
clang file.c -o file
would result in file.c being compiled into an executable file called “file”
What clang flag controls the warnings that clang produces?
-w
How do you turn on all warnings in clang?
-wall
How do you stop the compiler from creating an executable if it hits an error?
-werror
What clang flag allows gdb to be run?
-gdb
What clang flag links libraries into your code?
-l
What is typecasting
A way of changing how the computer interprets data, either implicitly or explicitly.
What can happen to precision during typecasting?
Precision can be lost, but never gained.
What part of a float is maintained if you cast it into an int?
The part before the decimal, all else is truncated (not rounded).
How is explicit typecasting done?
(type) variable
example: (int)x
What is implicit typecasting?
When the computer automatically casts into another type.
An example is adding an int and a float. The int is automatically cast into a float so that the operation can be performed.
Can implicit typecasting happen with the and == operators?
Yes
What is the difference between i++ and ++i?
When i++ i used, the value of i is used in the expression then the incrementing happens.
With ++i, the incrementing happens first.
Which happens first, incrementing or dereferencing?
Incrementing.
What must be done before a variable can be used?
It must be declared.
When naming variables, how are words separated?
With an underscore.
this_is_a_name
While C does not use this for variable names, what is camel case?
When the first word is lower case, and the first letter of following words is capitalized.
thisIsCamelCase
What is happening when you assign one variable to another variable? i.e x = y
The value of x is set to the value of y, but it is a copy, not a pointer to the same value as y.
Changing y later will not change x.