#include <stdio.h>
int main(void) {
unsigned int number = 4294967295;
int number_size = sizeof(number);
printf("%p\n", &number);
printf("%i\n", number_size);
return 0;
}
A program is a specific set of instructions written in a programming language designed to carry out a specific task. The plain text, human-readable, written instructions of a program are called the program’s source code. Anything that runs on a computer is a program.
These instructions are built from a few core ideas: syntax, statements, expressions, and data.
A programming language is a language that a program is written in. Programming languages are described in terms of their syntax and their semantics. Every programming language has different syntax and semantics.
Programming languages can be broken down into two main categories: high-level languages and low-level languages.
Assembly language is a human-readable version of machine language and is machine-dependent, meaning that the instructions and syntax used are specific to the computer’s CPU instruction set architecture (ISA). Different CPUs have different mnemonics, which are short abbreviations or symbolic names that represent machine language instructions (INP, OUT, ADD, MOV). Some popular assembly languages include x86 assembly, ARM assembly, and MIPS assembly.
Machine language, also known as machine code, is the elemental language of computers, and consists of machine language instructions that are composed entirely in binary. These binary numbers can be represented by using hexadecimal and correspond to commands or operations that tell the machine’s components exactly what to execute. It is the only language that computer hardware can understand.
Comments allow developers to write notes for humans. These notes are ignored by the computer. Comments explain code and help made it readable.
# This is a comment in a shell script!
The two fundamental aspects of a program are expressions and statements.
A statement is a single line of code or code block that instructs the computer to do something, such as assigning a value to a variable, calling a function, or controlling the flow of a program. Programs are mostly sequences of statements.
x = 10
print(x)
An expression evaluates to a value. Expressions are often used inside statements.
2 + 3 # evaluates to a number
x * 10 # evaluates to a number
x > 5 # evaluates to True or False (boolean)
A variable is a named container used to store an expression, statement, or function. Variables are newly created location in memory used to store and persist data that allow for easy access and reusability.
name = 'Grant'
Data refers to a collection of values that convey information for reference or analysis. A datum is an individual value within that larger collection of data.
All data has a data type, which is a classification on what type the data or datum is. Data can be anything: numbers, letters, sentences, special characters, a combination of numbers and letters etc.
There are three main data types in a program:
5 # integer
3.14 # float
"Grant" # string
False # boolean
Data types matter because different operations work on different types, and mistakes can cause errors.
Operators do things to values. They perform operations on data. They can either combine or compare values, and are usually part of expressions.
Different types of operators:
+ - * / % # arithmetic
== != < > <= >= # comparison
and or not # logical
Control flow refers to how a program flows or the steps it takes from start to finish. There are many ways to control the flow of a program:
A program will execute instructions sequentially, line-by-line, until all the instructions have been executed. The issue with this is programs can get very long, very fast. We can better organize programs through control structures (jumps, selections, iterations) and subroutines.
A conditional asks questions and makes decisions in code.
There are different types of conditionals: if, if/else, if/elseif/else.
if age >= 18:
print("Adult")
else:
print("Minor")
A loop repeats actions. Recursion is also another form of a loop that calls itself.
for i in range(3):
print(i)
for (int i = 0; i < 10; i++) {
printf('Hello!');
}
A function is a grouping of statements that perform a specific task. Functions can be reused and help to organize code and reduce the total number of lines of code that need to be written. The answer returned by a function is known as the return value of the function.
Functions can be ran immediately or at a later time in the program. Functions that run immediately and don't have a name are known as anonymous functions, while functions that can run at a later time and do have a name are known as named functions. Named functions commonly have a name that describe the task they're performing.
Parameters are the labels used when declaring a function, while arguments are the specific values used when calling a function.
function greet(name) {
console.log(`Welcome ${name}!`);
}
greet('Grant');
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const grant = {
"name": "Grant",
"age": 29,
"location": "Erie, Colorado"
}
A data structure is a way to organize, store, and access data. Some common data structures include:
Linked Lists – A sequence of nodes where each node points to the next. Useful for efficient insertion and deletion.
Stacks – Collections of elements that follow Last In, First Out (LIFO). Think of a stack of plates.
Queues – Collections of elements that follow First In, First Out (FIFO). Like a line at a checkout.
Priority Queues / Heaps – Special types of queues where each element has a priority, and the highest (or lowest) priority element is served first.
Tries (Prefix Trees) – Trees used to store strings efficiently, often for searching words in dictionaries or autocomplete.
Linked Hash Maps / Ordered Dictionaries – Variants of hash maps that maintain insertion order.
A programming paradigm is a way in which a program or programming language can be organized. Each paradigm consists of certain structures, features, and opinions about how common programming problems should be tackled.
A programming paradigm can be thought of as a set of ideals or guidelines that many people have agreed on, followed, and expanded upon.
A class is a blueprint for an object. Classes define attributes and properties (data) and methods and behaviors (functions) that the objects created from them will have.
Methods are functions that are created inside (and are part of) an object.
An object is an instance of a class. Each object is a specific, usable version of the class that has its own attributes and methods and actual values for its properties.
In order for a program to be read and executed by the computer’s hardware, there needs to be a system in place that translates the program’s source code into machine code so the computer can understand it. That’s where a programming language implementation comes in. A programming language implementation is a system for executing computer programs. There are two general approaches when it comes to programming language implementation:
Interpreters and compilers both take source code and convert it into computer-readable machine code. However, there are some key differences.
Interpreters run slowly but start translating line-by-line right away, and let you see the results quickly. This makes it easier to write, debug, and modify the source code if there are any problems. Interpreters are also programming language specific, meaning that every interpreted programming language needs its own interpreter to execute the program's source code.
Compilers require some extra preparation time at the beginning to "build" the program, but once built, the program runs very quickly. Compilers are programming language specific, meaning that every compiled programming language needs its own compiler to execute the source code. Compilers are also machine-specific and specific to a CPU's ISA.
Assemblers are programs that translate assembly language into machine code. Their input is low-level code.
Below are some examples of different types of programming languages.
A script is a series of short instructions that a computer can follow to achieve a specific goal, or to automate an otherwise manual process. A script can be thought of as similar to a recipe, a handbook, or a manual - it is a sequence of steps that, when followed, produces a desired outcome. A web browser may use different parts of a script depending on how the user interacts with the web page. Scripts can run different sections of code in response to the ever-changing situation around them. Scripts are meant to help with automation, reducing repetitiveness, and increasing productivity.
Some examples of different types of scripting: