Progweek1 Flashcards
Unix was born in _
1973
Unix provides a _ between the _ and the _.
simple-to-use and powerful interface
user (the programmer)
hardware (the computer)
Unix was based on simple ideas:
1
2
3
4
- simple interface
- simple instructions that can be combined
- hierarchical file system
- independent from specific computer architectures
Since its development, Unix served as a _
base to develop operating systems
structure of systems developed by Unix:
⥐⥐⥐
1 ⇋ 2 ⇋ 3 ⇋ 4
1: user
2: shell
3: kernel
4: Hardware
2&&4: OS
The Unix shell is _.
It allows _.
an interface between the user and the operating system.
to run system commands.
why a shell?
- powerful: Allows to solve
many simple problems in a few
lines. - Fast && flexible: offers
a scripting language which
often results in faster solutions
to problems.
syntax of commands
<options><parameters>
</parameters></options>
what is the command to list ll the file and directories in my desktop
l s −a
command that shows you the manual of the
specific command
+give eg
man
eg: man ls)
To work with objects in the file system we use their paths. There are two
ways of expressing the path of a file:
- Absolute: Starting from the root, e.g.: /Users/Lorenzo/Desktop
- Relative: Starting from the current
position in the file system,
e.g.: ./Lorenzo/Desktop
“..”
meaning on the shell?
“the parent directory”
“.” meaning on the shell?
“this directory”
def of Files:
A sequence of bytes.
def of Path: (+eg)
The position in the file
system,e.g., /Users/Lorenzo/Desktop
def of Permission:
What can a user do with
the file read/write/execute for the owner,
owner group, everyone
hox to see permission on the shell?
use option ls -l
def of Directories:
A file that indexes other
files.
main ingredients of the file system:
- files
- path
- permission
- owner
- dimension
- last modified
- directories
list the files in dir
ls dir
count words in file
wc file
count characters in file
mc file
count lines in file
lc file
look for all the lines in the file that match the expression
grep expression file
redirects the output of the command to a file
command > file
edirects the output of the command to a file with append
command»_space; file
use the ouput of command1 as input of command2
command1 | command2
command1 is executed successfully
executes command2
command1 && command2
Vim is a _ yet quite _ file _.
minimal
powerful
file editor
In a few words, C is:
- Imperative
- Typed
- Low level
pros of C
- Efficient (you have full control
on use of resources) - Fast (you can usually
implement very fast programs,
e.g., using bit manipulation) - Good if you want to implement
low level applications
cons of C
Limited degree of abstraction
Limited run time support
Limited portability
Low level of security
what is “int main()” ?
declares a function which is called “main” and returns an
integer.
def of Interpreter:
Program that executes code written in the high-level language. This is the typical approach of functional and scripting languages, standard in Python.
def of compiler
The compiler translates the code to the target language
producing an executable file. This is the standard approach in most
imperative languages, standard in C.
C programs are complied:
hello.c → 1 → 2 → 3 ⇒ 4
- preprocessor
- compiler
- linker
- executable code
Preprocessing:
takes care of lines that start with “#”
Compiling:
takes the code obtained from the preprocessor and
produces code that can be executed by the hardware
Linking:
links the object file to external libraries
This is how you should compile your programs:
gcc -Wall -pedantic -g -o helloworld helloworld.c
When you want to learn a new language there are a few things you need
to check:
The paradigm: Imperative, functional, logic, etc.
The type system: Typed/Untyped, explicit/inferred, type operators,
etc.
the basic syntax
scope of names
parameter passing
memory management
def of commands
give eg
roughly, a command is a piece of code that changes the
memory (i.e., in general commands do not return values). The main
example is assignment which assigns a value to a variable (i.e.,
essentially a piece of memory with a name).
def of expressions
give eg
expressions are roughly pieces of code that can be
evaluated to obtain a value, e.g., 3 + 2, x + y , sin(3) are all
expressions.
Programming languages can be roughly divided as follows:
imperative
functional
logic
object-oriented
def of imperative:
give eg
Programs have a state (snapshot of memory, instruction
counter, etc.) and consists of a sequence of commands (Examples: C,
Pascal, etc).
def of functional
give eg
A program consists of function declarations and compositions.
Problems are solved in a way that is closer to how we think in mathematics.
(Examples: Racket, ML, Haskell, etc)
def of logic
give eg
A program consists of a collection of logical clauses which describe
properties of the problem and of the solution. The execution of the program
finds a solution matching the requirements. (Examples: Prolog, ASP, etc) .
def of object oriented
give eg
This programming approach uses “objects” which contain data and operations. It’s often combined with other programming styles. Examples of OOP languages are C++, Python, Java, and Ocaml.
very program has the
following structure:
1
2
3
- preprocessor directives
- global declaration
- function implementation
To work with data in our programme we use two basic constructs:
- variables
- constants
def of variables
a piece of memory with a name (called identifier) whose
size depend on the type of the content and whose content can change
during the execution of the program.
def of constants:
a piece of memory with a name whose size depend on the
type of the content and whose content cannot be changed during the execution of the program.
def declaration:
we specify the name and type of the variable (memory is
allocated).
def initialization:
we assign a value to a variable for the first time.
A data type is:
- a collection of objects ({. . . , 1, 0, 1, 2, . . .} for int)
- a collection of operations (+, ⇤, , / etc. for int.)
Primitive types:
these are the types that are available to the
programmer as building blocks of their program.
Type constructors:
these are ways of defining new types.
C is a _ programming language. This mean that variables, constant,
and expressions will contain/express only data of _.
typed
a specific type
Types in
C must be mentioned _
explicitly
include <stdio.h> ?</stdio.h>
includes the standard input-output library functions in a C program, such as printf and scanf.
& in scanf(%d, &i):
is used to tell scanf the location (address) in memory where it should store the integer that it reads from the user input.
Variables of type char are of _ byte(s) (_ bits) and can therefore
represent _ = _ characters.
one
8
2^8
256
To check the size that a variable of a certain type occupies you can
use the function __ which returns the dimension in bytes
of the given type.
sizeof(type)
The types float and double are used to represent __.
real numbers
All floating types are _numbers
can you use the unsigned modifier?
signed
no
Float are usually _ bytes long and double _ bytes long.
4
8
The operator % is the modulo operator,.e.g,. 3%2 is 1. This operator
cannot be used with __.
double and float
property of types:
- → - → - →- → -→ _
char → int → long → float→double → long double
how to do 2^5
pow(2,5)
how to do |-5|
fabs(-5)
False is represented by _
0
True is represented by any value _
bigger than 0
The most immediate application of boolean expressions are __
conditional statement
Statements in a program are executed one after each other; this is know as _
sequential flow control.
In C, a loop consists of two parts: the _ and the _
body
control statement
A control statement :
indicates the condition(s) driving the loop by
executing the body until the condition or conditions become False.
In C, the looping statements are classified into two types:
Entry controlled loop
Exit controlled loop
Entry controlled loop:
the condition is checked before execution of the body.
Exit controlled loop:
the condition is checked after execution of the body.
while-loops, entry- or exit controlled?
entry
for loops, entry- or exit controlled?
entry
do-while loops, entry- or exit controlled?
exit
if, if-else, and switch are _
conditional statements
As you already have experience, if we are not careful we can end up in a case in which the expression will never become zero. This will lead to an _ , and we will be stuck forever!
infinite loop
The condition in for loops is _ ; if it is nonzero (True),
control passes back to the beginning of the loop, and it stops
when False is returned.
a logical expression
f o r ( 1; 2; 3) {
4 ;
}
- initialization
- condition
3.update - statements
what does the do-while loop tests?
It tests the termination condition after each pass through the loop
body. The body is executed at least once!
the break statement is a special command that _ _. It stops
__ a loop
interrupts the flow of control
prematurely
the switch statement:
It is a way to generalize the conditional (if-else) statements. It compares constants.
def of function:
is a block of code -or collection of statements- that runs when
is invoked. We can pass data (parameters) into a function.
In C, the main() function is __. It is user-defined and mandatory!
”the entry point of a program where the execution starts”
the main function is called by the _, not the _
OS
user
i n c l u d e <s t d i o . h>
i n t a = 3 3 ;
i n t main ( ) {
i n t b = 7 7 ;
p r i n t f ( ” a = %d\n” , a ) ;
p r i n t f ( ”b = %d\n” , b ) ;
r e t u r n 0 ;
}
what is the global and the local variable?
local: b
global: a
Local variables :
are declared in the body of a function
Global variables :
are declared outside of any function, and are available
for any routine in the program
unction prototype:
t y p e f u n c t i o N a m e ( p a r a m e t e r s ) ;