Cs50 Flashcards
Cs50 library
Include < Cs50.h>
General C library
include
standard io(input/outputs functions)
Int
What is it?
How many bytes /bits of memory?
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 can you double the value that an integer or other data type can take on?
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
Char
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
Floating point numbers (float)
Real numbers with decimals.floats have a precision problem because with only 32 bits
Double
Data type like a float but fit 8 bytes so double precision
What is type, but not a data type?
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
Bool
data type;only capable of 2 values true or false.
In C, every non-0 number is true, 0 is false
String
data type;
Text→ vanables that will store a series of characters (words,sentences, paragraphs, etc.)
Struts/typedefs
Structures and defined types
What 2 things do you need to create a variable?
① give it a type
② give it a name
int number;
char letter;
How do you create multiple variables at once for a given type?
int height, width;
float sqrt2,sqrt3, pi;
Initialization
When you declare a variable and assign it @ the same time.
int number =17;
Arithmetic operators
Add +
Subtract -
Multiply *
Divide /