CS50 Week 2 Flashcards

1
Q

How many bits is an int?

A

32

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

How many bits is a long long

A

64

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

How many bits is a float?

A

32

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

How many bits is a double?

A

64

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

How many bits is a char?

A

8

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

Reminder: variables declared inside curly braces have scope limited to within the curly braces.

A

Reminder: variables declared inside curly braces have scope limited to within the curly braces.

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

How do you declare a global variable?

A

Declare it before main()

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

What is the function that gives a string’s length, and where is it found?

A

strlen(string)

string.h

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

How is a variable declared?

A

type name(parameter)

Type is the data type that will be returned

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

What is the type of a function that returns no value?

A

void

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

Where is a function declared?

A

The name should be declared above main()

The actual body of the function should be declared after main()

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

How many numbers can be represented by a 32 bit int?

A

2^32

roughly four billion

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

How do you cast numbers into a type while in an equation?

A

(float) 1

(float) #

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

Why can we convert between chars and ints?

A

Because chars are actually number values that correspond to symbols per ASCII

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

What is one thing that marks the limit of scope in C?

A

Curly braces.

Any variable declared inside a set of curly braces does not exist outside the curly braces.

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

How is a global variable declared in C?

A

It is declared before the main() function.

17
Q

Why can you access an individual character within a string?

A

Because strings are implemented in the CS50 library are actually arrays of chars.

18
Q

How do you access a certain element of a string?

A

stringName[i]; where i is the index of the character you want to access.

Counting starts at 0.

19
Q

Where is a user made function declared?

A

Above main(), if it will be used in main().

20
Q

What is the sentinel value that GetString() returns when the function fails to get a string?

A

NULL

21
Q

How do you declare multiple variables in one line?

A

int a = 0, b = 1 …

22
Q

What C library contains functions that classify and transform individual characters?

A

ctype.h

23
Q

When are curly braces not needed for if-else blocks?

A

When the following code is only one line.

24
Q

How do you access the man pages?

A

type “man functionName”

25
Q

What is the physical representation of the NUL character?

A

\0

26
Q

What is the primary purpose of an array?

A

To store multiple instances of a data type in one place.

27
Q

How do you declare an array?

A

i[#]

where # is the number of elements in the array.

28
Q

How are command line arguments established, according to convention?

A

int main(int argc, string argv[])

29
Q

What is argc?

A

Argument count

It is an int describing the number of arguments passed to main(). The name of the program counts as one argument.

30
Q

What is argv[]?

A

An array of the arguments themselves.

The first element (the 0th element) is always the name of the program.

31
Q

What is argv[] in actuality, given the nature of strings?

A

Because a string is an array of characters, argv[] is an array of arrays.

32
Q

How would you access a certain character in a command line argument?

A

argv[i][n]

where i is the string you are trying to access, and n is the individual char within the string.