Cs50 Flashcards

1
Q

Cs50 library

A

Include < Cs50.h>

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

General C library

A

include

standard io(input/outputs functions)

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

Int
What is it?
How many bytes /bits of memory?

A

C data type/variable;
Used for variables that will store
4 Bytes/32 bits
Range from -2^31 to 2^31 minus 1 because we need as spot for 0

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

How can you double the value that an integer or other data type can take on?

A

Use “unsigned” qualifier;
Ex.) unsigned int → useful when you need a larger range and don’t need negative numbers;

Rangefor unsigned int = 0 to 2^32-1

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

Char

A

1 byte 18 bits; a single character;
Range from -2^7 to 2^7-1 (-128 to 127)
ASCII has single characters, or chars, mapped to numbers
Ex A =65; a=97

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

Floating point numbers (float)

A

Real numbers with decimals.floats have a precision problem because with only 32 bits

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

Double

A

Data type like a float but fit 8 bytes so double precision

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

What is type, but not a data type?

A

void
Can’t create a data type of “void” and assign a value to it
But it can be a return type in a function.
Printf→ doesn’t return a value

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

Bool

A

data type;only capable of 2 values true or false.

In C, every non-0 number is true, 0 is false

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

String

A

data type;

Text→ vanables that will store a series of characters (words,sentences, paragraphs, etc.)

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

Struts/typedefs

A

Structures and defined types

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

What 2 things do you need to create a variable?

A

① give it a type
② give it a name

int number;
char letter;

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

How do you create multiple variables at once for a given type?

A

int height, width;

float sqrt2,sqrt3, pi;

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

Initialization

A

When you declare a variable and assign it @ the same time.

int number =17;

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

Arithmetic operators

A

Add +
Subtract -
Multiply *
Divide /

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

Modulus operator %

A

Gives us the remainder
Ex. int m= 13 % 4 // m is now 1

Random number generator →

17
Q

Equivalent syntax for

x = x * 5;

A

X *= 5;

18
Q

X++;

X–;

A

Increase or decrease variable by 1

19
Q

Logical operator

A

AND (&&)
x && y ;

Boolean expression where both operands are true, otherwise false;

OR (| |)
True if and only it @ least one of the operands is true
x || y
X can be true, Y can be true, X and y can be true, but both can’t be false

NOT (!) → inverts value of its operand, also called bang
If x is true, !x is false
If x is false, !x is true

20
Q

Relational operators

A
x < y
X <= y
X > y
X >= y
X == y equal
X !=y not equal
21
Q

Conditional expressions

if else

A

If (boolean-expression)
{

}
else (boolean-expression)
{

}

22
Q

How can you write a simple if else conditional on one line?

A

int x = (expr) ? 5 : 6;

Here, if expression is true, assign value of 5, else assign it a value of 6

23
Q

Switch conditional

A

Use discrete cases to make decisions

24
Q

While Loops

A

While (true)
{

}

This is a forever loop.

While (boolean-expression)
{

}

25
Q

Do while loops

A

do
{

}
While (boolean-expression);
Do-white is guaranteed to run @ least once.

26
Q

For loop

A

Used to repeat something a specific number of times

for (int i = ; i < 10; i++)

27
Q

Linux command line

A
ls → list
cd→ change directory
pwd → present working directory
mkdir → make directory
cp   → copy from a source to a destination
rm 
mv   → mv from a source to a destination