CS50 Week 1 Shorts Flashcards

1
Q

Who were boolean values named after?

A

George Boole

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

What are the two possible conditions of a boolean value?

A

True and False

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

What are the boolean operators in C?

A

And &&
Or ||
Not !

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

what are the possible permutations of an AND expression?

A

TRUE and TRUE = TRUE
TRUE and FALSE = FALSE
FALSE and TRUE = FALSE
FALSE and FALSE = FALSE

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

What are the possible permutations of an OR expression?

A

TRUE and TRUE = TRUE
TRUE and FALSE = TRUE
FALSE and TRUE = TRUE
FALSE and FALSE = FALSE

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

What doe the NOT operator do?

A

It takes a boolean operator and returns the opposite of it.

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

What are the numerical representations of TRUE and FALSE in C?

A

0 = FALSE

Everything else = TRUE

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

What are the four major steps of the clang compiler?

A

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.

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

What does the pre-processor do?

A

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.

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

What is the clang command to only run the pre-processor?

A

-E

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

What is the clang command to send your output to a new file?

A

> filename.c

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

What is done during the compiling portion of the compilation process?

A

The source code is converted to assembly code.

This is called compiling into assembly code.

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

What is the clang command to only run through the compilation step?

A

-S

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

What happens during the assembly portion of compilation?

A

The assembly code is converted into “object code,” or “machine code”.

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

What is machine code?

A

The actual 1’s and 0’s that the computer can read.

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

Why is the same source code compiled into different assembly code on different computers?

A

The assembly code is processor specific.

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

What is the clang command to only go through the assembly phase of compilation?

A

-c

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

What happens during the linking phase of the compilation process?

A

The linker combines together object code from different files into one file.

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

Why is it a good idea to run clang on every file?

A

Because linking can be very system specific.

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

What must be contained in at least one of the object files?

A

a main() function.

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

What is the clang command to link a file into the finished file?

A
  • l + the file name.

- lname

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

Where do -l arguments go?

A

The end of the clang command.

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

Where do -l arguments go?

A

The end of the clang command.

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

What are three other terms for functions?

A

procedures, sub-routines, and sub-programs

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

What is the term for the organizational benefit of functions?

A

encapsulation

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

What are the inputs to a function called?

A

Arguments, or parameters.

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

Must a function take an argument, or return something?

A

No to both

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

What is the term for the declaration of a function?

A

The prototype

29
Q

What is the return type for a function that returns nothing?

A

void

30
Q

What is a side effect?

A

When a function has an effect other than its return value.

31
Q

What is the return type of main()?

A

int

32
Q

What are the arguments allowed for main()?

A

int argc

char* argv[]

33
Q

What does argc contain?

A

The number of command line arguments passed into the program.

34
Q

What does char* argv[] contain?

A

The string representations of the command line arguments passed.

35
Q

In general, what is a library?

A

a collection of related, prewritten code.

36
Q

What kind of files does a library consist of?

A

A library is a binary file that has been produced by linking together a collection of object files using a linker.

37
Q

What two kinds of files do libraries typically consist of?

A

header files and implementation files.

38
Q

What is the file extension for a header file?

A

.h

39
Q

What does a header file describe?

A
The resources available in the library. This can include:
functions
variables
structs
type definitions
etc.
40
Q

What is a common term for the resources described in a header file?

A

The interface.

41
Q

Why are there no function definitions in the header file?

A

Information hiding, or encapsulation. It protects the user from changes in implementation.

42
Q

What is the file extension for the implementation file?

A

.c

43
Q

What does the binary library file consist of?

A

The header and implementation files, after they have been compiled and linked together.

44
Q

What will the library writer ship?

A

The header file and the binary file.

45
Q

What two things are needed to use a library?

A

include the header file above main()

Link the binary file during compilation.

46
Q

What are the two syntaxes used to include a header file?

A

include if the header file is in the default include library, which is typically usr/include.

47
Q

What is make?

A

A program that organizes invocations of commands to the compiler, ensuring that things are compiled in the proper order and in the proper way.

48
Q

What is the make command to compile a file?

A

make file

49
Q

What is the default output for clang?

A

a.out

50
Q

At the most basic level, what is the command to run clang on a file?

A

clang file.c

51
Q

What is the clang command to control what the name of the output is?

A

-o

clang file.c -o file
would result in file.c being compiled into an executable file called “file”

52
Q

What clang flag controls the warnings that clang produces?

A

-w

53
Q

How do you turn on all warnings in clang?

A

-wall

54
Q

How do you stop the compiler from creating an executable if it hits an error?

A

-werror

55
Q

What clang flag allows gdb to be run?

A

-gdb

56
Q

What clang flag links libraries into your code?

A

-l

57
Q

What is typecasting

A

A way of changing how the computer interprets data, either implicitly or explicitly.

58
Q

What can happen to precision during typecasting?

A

Precision can be lost, but never gained.

59
Q

What part of a float is maintained if you cast it into an int?

A

The part before the decimal, all else is truncated (not rounded).

60
Q

How is explicit typecasting done?

A

(type) variable

example: (int)x

61
Q

What is implicit typecasting?

A

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.

62
Q

Can implicit typecasting happen with the and == operators?

A

Yes

63
Q

What is the difference between i++ and ++i?

A

When i++ i used, the value of i is used in the expression then the incrementing happens.

With ++i, the incrementing happens first.

64
Q

Which happens first, incrementing or dereferencing?

A

Incrementing.

65
Q

What must be done before a variable can be used?

A

It must be declared.

66
Q

When naming variables, how are words separated?

A

With an underscore.

this_is_a_name

67
Q

While C does not use this for variable names, what is camel case?

A

When the first word is lower case, and the first letter of following words is capitalized.

thisIsCamelCase

68
Q

What is happening when you assign one variable to another variable? i.e x = y

A

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.