1/64
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Variable
A place where data can be stored, including a name, a place in the memory, and a stored value
Variable Declaration
A statement we use to tell the compiler about a variable
Variable Format
<type> <variable name>;
int
integer, meaning whole number
double
real number, which includes fractions, decimals, integers
%f
floating-point (real numbers)
%10.2f
0 total characters (including the decimal point) with 2 of them being decimal places. So that will be 7 positions for the integer part (with one being the negative sign if we need one), one for the decimal point, and two for the fractional part. The integer positions will be left padded with spaces if the number doesn’t fill them and the fractional part will be right-filled with zeroes if necessary.
%d
integers
%c
character
printf
the code that comes from the stdio library (must have #include <stdio.h> in the code) and is how outputs are sent to the screen
Format String
Specifies how our values should be formatted
Prompt
Telling the user what we want them to do
\n
Hits enter when printing a line
Integer Division
Division between 2 integers, quits at the decimal point
Real Division
Division between 1 or more real numbers, divides all the way
scanf
Gets input from the keyboard
Mod Operator (%)
Gives the remainder after division
# (Pound)
Signifies a directive to the compiler’s preprocessor
#define
Tells the preprocessor to replace the <name> with the <stuff> throughout the code.
=
Means to assign a value
==
Means equal to
{ } Curly Brackets
Surround blocks of code, used to encase the information inside of functions
Reserved Words
(int, double, return, etc.) are always lowercase and should never be the name of a variable or parameter
Standard Identifiers
Redefined by the programmer, e.g. scanf, printf, variables.
Right Hand Side
Expression that evaluates what we want to store
Left Hand Side
Variable we want to store the result
Input Operation
Get data from the world
Output Operation
Get data to the world
Why do we use two's complement over one's complement?
There is only one way to encode 0
x = 42;
x gets the value of 42
#include
The #include directive tells the preprocessor to get another file, copy its content, and then insert it into the source code.
Signed Magnitude
Top bit as sign bit, two ways to represent 0
One’s Complement
Negation, flip all the bits, two ways to represent 0
Two’s Complement
Negation, flip all the bits and add 1, only one way to represent 0
byte
an integer type that holds 8 bits
char
Holds characters stored in ASCII
short
An integer type that holds at least 16 bits
Declaration Of A Function
return type> <function name> ( <parameter list> ) { <code> }
Increment ++
Add one
Decrement - -
Subtract one
Call Stack
Shows the order of the functions that are called in the c file. It keeps track of the variables for each in-progress call and the information necessary to return from one call to the place it called.
RSP (Stack Pointer)
Top of the stack
Write an assignment statement that will convert that to uppercase and store it into a char variable named upper_ch.
upper_ch = (char)(ch - ('a' - 'A'));
RBP
Points to the base of the currently executing stack frame
If Statements
If the condition is true, the compiler will complete the code in the then block, if not true it will skip the then block
If-Else Statements
If the condition is true, it will run the code in the then block, if false it will run the code in the else block
&&
Logical AND, true if both operands are true
| |
Logical OR, true if either operand is true
!
Logical NOT, true if the operand is false
Border Case
A situation where a small change in values causes a fundamentally different behavior
assert(<condition>)
Just makes sure that certain condition is true. If so it keeps running the code. If not, the code is stopped and an error occurs.
Switch Statements
A way to select one code block to execute from multiple options, based on the value of an expression
Header Guard
In case one include file includes others and that makes one source file accidentally include it more than once.
CMake
Tool that lets us specify how our projects should be built
#ifndef
Taking groups of related functions and putting them into different .c files makes it easier to read the code and not be so confusing.
Enums
Type we create that has a discrete ordered set of values
While Loop
A condition is evaluated and if it is true, the information inside the loop happens, and then it goes back to the top and evaluates the information again. This will continue until the condition evaluates to false at which point execution continues beyond the end of the while loop will run if that condition is true
While Loop Format
while(<condition>)
{
// what is done
}
For Loop Format
for(i=0; i <condition>; i++)
{
//what is done
}
Count-Controlled Loops
Stops when the loop has happened a specific number of times. Before the loop starts, we’ll know how many times it will run. For loops are preferred for count-controlled loops.
Sentinel-Controlled Loops:
These loops run until a particular condition is true and they may run any number of times before that condition becomes true (we don’t know ahead of time). Generally, we code sentinel-controlled loops using while statements.
Short-Cutting Evaluation
When we are building conditions that include && or ||, the order of the operations matters
The machine will evaluate the left-hand operand first. If that determines the value of the && or ||, the right-hand operand will not be evaluated.
Guard Conditions
These are extra terms that help stop a loop before wandering off the end of the array.
Break
The statement that is true will run and then the break stops the loop and jumps to the first line after the loop body (“getting out” of the loop)
Continue
It takes you back to the top of the loop and therefore skips the rest of the loop body for that pass through the loop. It is most commonly used when you are going through a big data set, but only want to do stuff to some of the records