CS50 Week 2 Flashcards
How many bits is an int?
32
How many bits is a long long
64
How many bits is a float?
32
How many bits is a double?
64
How many bits is a char?
8
Reminder: variables declared inside curly braces have scope limited to within the curly braces.
Reminder: variables declared inside curly braces have scope limited to within the curly braces.
How do you declare a global variable?
Declare it before main()
What is the function that gives a string’s length, and where is it found?
strlen(string)
string.h
How is a variable declared?
type name(parameter)
Type is the data type that will be returned
What is the type of a function that returns no value?
void
Where is a function declared?
The name should be declared above main()
The actual body of the function should be declared after main()
How many numbers can be represented by a 32 bit int?
2^32
roughly four billion
How do you cast numbers into a type while in an equation?
(float) 1
(float) #
Why can we convert between chars and ints?
Because chars are actually number values that correspond to symbols per ASCII
What is one thing that marks the limit of scope in C?
Curly braces.
Any variable declared inside a set of curly braces does not exist outside the curly braces.
How is a global variable declared in C?
It is declared before the main() function.
Why can you access an individual character within a string?
Because strings are implemented in the CS50 library are actually arrays of chars.
How do you access a certain element of a string?
stringName[i]; where i is the index of the character you want to access.
Counting starts at 0.
Where is a user made function declared?
Above main(), if it will be used in main().
What is the sentinel value that GetString() returns when the function fails to get a string?
NULL
How do you declare multiple variables in one line?
int a = 0, b = 1 …
What C library contains functions that classify and transform individual characters?
ctype.h
When are curly braces not needed for if-else blocks?
When the following code is only one line.
How do you access the man pages?
type “man functionName”
What is the physical representation of the NUL character?
\0
What is the primary purpose of an array?
To store multiple instances of a data type in one place.
How do you declare an array?
i[#]
where # is the number of elements in the array.
How are command line arguments established, according to convention?
int main(int argc, string argv[])
What is argc?
Argument count
It is an int describing the number of arguments passed to main(). The name of the program counts as one argument.
What is argv[]?
An array of the arguments themselves.
The first element (the 0th element) is always the name of the program.
What is argv[] in actuality, given the nature of strings?
Because a string is an array of characters, argv[] is an array of arrays.
How would you access a certain character in a command line argument?
argv[i][n]
where i is the string you are trying to access, and n is the individual char within the string.