Termbank
  1. A
    1. Abstraction
    2. Alias
    3. Argument
    4. Array
  2. B
    1. Binary code file
    2. Binary number
    3. Bit
    4. Bitwise negation
    5. Bitwise operation
    6. Byte
  3. C
    1. C library
    2. C-function
    3. C-variable
    4. Character
    5. Code block
    6. Comment
    7. Compiler
    8. Complement
    9. Conditional statement
    10. Conditional structure
    11. Control structure
  4. D
    1. Data structure
    2. Duck typing
  5. E
    1. Error message
    2. Exception
  6. F
    1. Flag
    2. Float
  7. H
    1. Header file
    2. Headers
    3. Hexadecimal
  8. I
    1. Immutable
    2. Initialization
    3. Instruction
    4. Integer
    5. Interpreter
    6. Introduction
    7. Iteroitava
  9. K
    1. Keyword
  10. L
    1. Library
    2. Logical operation
  11. M
    1. Machine language
    2. Macro
    3. Main function
    4. Memory
    5. Method
  12. O
    1. Object
    2. Optimization
  13. P
    1. Parameter
    2. Placeholder
    3. Pointer
    4. Precompiler
    5. Precompiler directive
    6. Prototype
    7. Python console
    8. Python format
    9. Python function
    10. Python import
    11. Python list
    12. Python main program
    13. Python variable
    14. Python-for
    15. Pääfunktio
    16. printf
  14. R
    1. Resource
    2. Return value
  15. S
    1. Statement
    2. Static typing
    3. String
    4. Syntax
  16. T
    1. Terminal
    2. Type
    3. Typecast
  17. U
    1. Unsigned
  18. V
    1. Value
  19. W
    1. Warning
    2. while
Completed: / exercises

Bits and Number Systems

Learning Objectives: After going through this material, you will understand how information is represented in a computer using binary numbers and you will be able to convert between different number systems used in computer technology.
In earlier programming courses, we learned which number systems are recognized by computers (and different programming languages): binary, decimal, and hexadecimal numbers. Of these, the decimal system is included only for us humans, i.e., programmers and users. The computer, being a humble calculator, only needs binary numbers, and low-level programmers need to know how the computer interprets binary numbers and their bits.

Bits in Computer Memory

A bit is the smallest part of an information element that can be processed. A bit has two mutually exclusive logical states, 0 and 1. The logical state here means that it is up to the processor, firmware/operating system, and programmer to decide what the bit states represent.
A single bit represents very little information, but when bits are placed in a sequence as a binary number, a wide variety of information can be represented. In previous lectures, we learned that the processor's architecture defines the size of the data element (word length) as an n-bit binary number.
For example, when dealing with a peripheral device in an embedded system, the logical state 0 could mean that the peripheral device is ready to receive commands, and 1 could mean that the device is busy, i.e., still processing the previous command.

Memory Location

It is generally straightforward and useful for the computer's memory to be organized into memory locations of the same size as the word length. This way, the word length (data bus) and memory size (address bus) determine the required width of the memory bus.
As an example, below is a snippet of memory from an 8-bit computer architecture. Now, the memory consists of only 16 memory locations, so the address bus width is 4 bits (2^4=16). (Such a small memory could be non-volatile EEPROM memory in an embedded device.)
Memory Address Content Interpretation in Decimal
0000 00000011 3
0001 11111111 -1
0010 10110111 -73
0011 00110110 54
.. .. ..
1111 00110111 55
In the memory above, at memory address 3 (0011), the value 54 (00110110) is stored. This situation could occur when we have declared an 8-bit variable in the program, which is initialized to the value 54. The compiler and operating system (without going into details) determined that this value should be stored at memory location number 3, from which it will be available to the program during its execution.
Example: You can easily think of the memory location address as a street address. 
Each house on the street has a number that uniquely identifies the house, 
and each house can store one piece of information. 
In the memory example above, the number 54 would be stored in house number 3, 
from which it can be retrieved or replaced with a new number.
(We will return to this house analogy in later material...)

Naming Conventions

Now, different-sized binary numbers have generally been given specific names in computer science:
It is important to be familiar with these terms as part of the professional skills of an information/electrical engineer, and they are commonly used in digital and computer technology.

Interpretation of a Binary Number

Unfortunately, it is not enough to simply associate the variable name in our program with a memory location and its value. Additionally, the computer must know how to interpret the binary number stored in memory.

Bit Order

When representing a binary number to the processor's arithmetic unit, there are still a couple of complications, as it must also be decided how the processor interprets the sequence of bits in a memory location.
In the decimal system, we have agreed that the most significant digit is the leftmost digit, with decreasing significance as we move to the right. For example, in the number 217, the greatest weight is on the digit 2, which represents hundreds. So, the number is 2 x 100 + 1 x 10 + 7 x 1 = 217. However, nothing but mutual agreement prevents us from reading the number in the opposite direction, 7 x 100 + 1 x 10 + 2 x 1 = 712.
The same applies to binary numbers. Now, for example, the number 1011 can be read either left to right or the other way around. Depending on the direction, the value of the number can change, which can cause confusion if there is no agreement.
"MSB and LSB"
When defining the direction of reading, we talk about bit order, which requires two definitions:
Well, the bit order has already been decided for us by the processor architecture designers. Since the direction can still vary even today, it is mentioned in the processor's manuals. Typically, the programmer does not need to pay attention to this aspect because in programming languages, the bit order can be defined as desired, and compilers will adjust the code to suit the processor. However, in embedded systems, when dealing with peripherals, you may need to pay attention to bit order.

Byte Order

It’s still not enough to know in which order the bit sequence of a binary number should be interpreted. Especially in embedded systems, we often deal with numbers that are larger than the word length!
For example, in an 8-bit embedded system processor architecture, we may commonly handle 16- or 32-bit numbers.
The solution is to split the number into chunks that fit the word length, so in an 8-bit architecture, a 16-bit number becomes two 8-bit numbers, and a 32-bit number becomes four 8-bit numbers. These numbers are then stored in consecutive memory locations. For example, in 8-bit Arduinos, C compilers generally allow the use of larger numbers, and the compiler adapts the code to suit the microcontroller (in machine code, operations on larger numbers must be done in steps).
Let’s revisit the memory example above:
Memory Address Memory Content Interpretation in Decimal
0000 00000011 3
0001 11111111 -1
0010 10110111 -73
0011 00110110 54
Now, in this memory dump (a raw copy of the memory contents), there are four bytes, which could represent four 8-bit numbers, two 16-bit numbers (memory locations 0-1 and 2-3), or one 32-bit number (memory locations 0-3). Okay, but… this raises the question of in which order the bytes should be read. Is the first byte of the 32-bit number in memory location 0 or 3?
Well, as expected, the byte order (i.e., the direction in which the bytes are read) has also been determined during the design of the processor architecture. Here, two general terms are used:
Example: The current x86-64 processor architecture used in PC workstations is little endian, 
but the bit order is most significant first, meaning bits are read from left to right, MSB -> LSB.

Agreement

To ensure we understand each other in this course, let's define the common reading directions:
Example: Interpretation of a 16-bit number.
MSB    ->    LSB
1100101000101100 = -13780

Striving for Efficiency

Great, but why are we so concerned about bytes and words? Wouldn't it be enough to always use 64-bit architecture in applications, so we never run out of range and compilers can handle large numbers?
When programming on a workstation, this isn’t usually a concern because there are plenty of resources like memory and processing power. However, in embedded systems, microcontrollers typically have a small amount of RAM, often just a few kilobytes, which must be shared between the application, firmware, and possibly the operating system. Therefore, memory usage needs to be carefully considered.
The key here is to use variables that are just the right size in the program. Now, if the number range we need fits within an 8-bit variable, why define a 64-bit variable for that purpose? In the latter case, memory usage would be eight bytes, whereas the application could actually get by with just one byte. For someone used to workstation programming, saving a few bytes may seem insignificant, but let's look at it from an embedded perspective with an example.
Example: ATmel's ATtiny series microcontrollers have RAM that is less than one kilobyte 
(1024 bytes). Let's do some calculations. Now, if 32-bit variables are used, the maximum number 
of variables that can fit in memory is (1024 bytes / 4 bytes = 256). If 16-bit variables are used, 
512 variables could fit in memory (1024 / 2 bytes = 512). But isn’t a hundred variables quite 
a lot for a single program?

Well, it depends on the application. For example, if we are collecting accelerometer data 
at a fast pace (several times per second) from three axes (X, Y, Z) into an array, a few kilobytes 
of memory may no longer be enough...
We will return to this topic in the next material, where we introduce the C language variable types.

Negative Binary Numbers

Earlier, we used binary numbers to represent positive numbers, but hey… what about negative binary numbers?
No worries, there are several solutions proposed in computer science, which are based on the agreement to reserve one bit of the binary number as a sign bit to represent the sign (+ / -). Typically, this bit is the MSB, where a value of 0 indicates a positive number, and 1 indicates a negative number. When one bit is reserved for the sign, we are left with n-1 bits for the actual number range.
For example, the number range of an 8-bit number is reduced to 7 bits, so the positive number range would be only 0..127. However, with the help of the sign bit, we can now include a negative number range of -128..-1. Without the sign bit, the number range would be 0-255, so the range effectively shifts in the negative direction by the value of the MSB.

Signed Magnitude

In the signed magnitude representation, the most significant bit (MSB) is reserved as the sign bit. This means, for example, that 0010 would be 2, and 1010 would be -2.
Notice that in this case, zero has two representations: 0000 (representing +0) and 1000 (representing -0). This is problematic because the program has to account for both representations of zero.

One's Complement

Now, a negative number is obtained by taking the logical negation of the positive number. For example, if the number 3 is represented as 0011 in binary, then -3 would be 1100.
In this representation as well, zero has two representations: 0000 and 1111, so it is neither ideal nor suitable for our purposes.

Two's Complement

The two's complement representation is commonly used in digital technology/computing, so we will spend a little more time and course material on it.
Again, let's agree that the most significant bit (MSB) is the sign bit, where 0 represents positive and 1 represents negative.
1. Take the negation of the positive binary number (i.e., flip the bits: 0s become 1s and vice versa).
2. Add 1 to the negated number.
Examples with 4-bit numbers.

Number 1    0001       Number 2    0010       
Negation    1110       Negation    1101  
Addition    +1         Addition    +1                  
            ----                  ----                
            1111 = -1             1110 = -2 
Conversion back from negative to positive is done in the same way (convenient!):
Number -1   1111       Number -2   1110      
Negation    0000       Negation    0001   
Addition    +1         Addition    +1                  
            ----                  ----                
            0001 = 1              0010 = 2
Example: The image shows 4-bit numbers without a sign and in two's complement representation.
"Number ranges"

Convenience

Two's complement is also convenient because the addition of two's complement numbers works the same way, whether the operand is positive or negative. This significantly simplifies the implementation of logic circuits that perform arithmetic in digital technology.
Example: Calculate with two's complement numbers 2+3 = ? and 2-3 = 2+(-3) = ?

Number +2  0010            Number +2  0010
Number +3  0011            Number -3  1101
+          ----            +          ----
           0101 = 5                 1111 = -1
In signed magnitude and one's complement representations, this doesn't always work. Try to find an example where addition fails!

Greetings from the Tricks Department

And now, a tip from the tricks department… converting a negative binary number to decimal can be done without a calculator by using simple addition. The idea is to think of it this way:
In the image below, the value of the MSB bit is considered negative, and the others are positive.
"Just simple addition"
Now, the conversion happens by adding together the decimal values corresponding to the bits.
Example: 8-bit numbers 99 and -99.

99 in binary is 01100011, which is 64 + 32 + 2 + 1 = 99
-99 in binary is 10011101, which is -128 + 16 + 8 + 4 + 1 = -99
Convert 2-complement 6-bit binary number 101011 to decimal system number.
Give just the result.
Warning: You have not logged in. You cannot answer.

Hexadecimal Numbers

Another number system often used in computer technology is base 16. Here, we are talking about hexadecimal numbers, which include the digits 0-9 and 10-15, where the latter are represented by the letters A-F.
"Hexadecimal numbers"
Notice that each hexadecimal digit can be represented with 4 bits (a so-called nibble). This is one of the main reasons why hexadecimal numbers are used in computer science and programming. Now, a byte can be represented by two hexadecimal digits (vs. a decimal number that is awkward to interpret as bits, or a binary number that is visually cumbersome).
Conversion between hexadecimal and binary numbers is easy once we know that each hexadecimal digit corresponds to 4 bits. You simply need to convert each hexadecimal digit to its 4-bit binary equivalent.
Example: The binary number 01011101 is hexadecimal 5D and in decimal is 93.
   5    D
0101 1101
0 + 64 + 0 + 16 + 8 + 4 + 0 + 1 = 93
Example: Convert the hexadecimal number 173A4C to binary?
   1    7    3    A    4    C   
0001 0111 0011 1010 0100 1100
In many programming languages, hexadecimal numbers are presented with the prefix 0x. For example, all of the following numbers are valid hexadecimal numbers.
0x0
0x0123456789ABCDEF
0xA
0x1000
0x001
0xBEEF
0xC0DE
0xBA5EBA11

Conclusion

... sometimes working with different number systems can take unexpected turns (http://www.xkcd.com/571)
"Counting sheep"
Well, now it's clear to us what happens in the third panel! Our friend is counting sheep using 16-bit two's complement numbers, and it so unfortunately happens that while waiting for sleep, the positive number range runs out, causing the sign bit to flip, and suddenly the count moves into the negative number range.
...
0111111111111111 = 32767 sheep
              +1 sheep
1000000000000000 = -32768 sheep // the sign bit flipped when MSB changed from 0 to 1
              +1 sheep
1000000000000001 = -32767 sheep
...
?
Abstraction is a process through which raw machine language instructions are "hidden" underneath the statements of a higher level programming language. Abstraction level determines how extensive the hiding is - the higher the abstraction level, the more difficult it is to exactly say how a complex statement will be turned into machine language instructions. For instance, the abstraction level of Python is much higher than that of C (in fact, Python has been made with C).
Alias is a directive for the precompiler that substitus a string with another string whenever encountered. In it's basic form it's comparable to the replace operation in a text editor. Aliases are define with the #define directeve, e.g. #define PI 3.1416
Argument is the name for values that are given to functions when they are called. Arguments are stored into parameters when inside the function, although in C both sides are often called just arguments. For example in printf("%c", character); there are two arguments: "%c" format template and the contents of the character variable.
Array is a common structure in programming languages that contains multiple values of (usually) the same type. Arrays in C are static - their size must be defined when they are introduced and it cannot change. C arrays can only contain values of one type (also defined when introduced).
Binary code file is a file that contains machine language instructions in binary format. They are meant to be read only by machines. Typically if you attempt to open a binary file in a text editor, you'll see just a mess of random characters as the editor is attempting to decode the bits into characters. Most editors will also warn that the file is binary.
Binary number is a number made of bits, i.e. digits 0 and 1. This makes it a base 2 number system.
A bit is the smallest unit of information. It can have exactly two values: 0 and 1. Inside the computer everything happens with bits. Typically the memory contains bitstrings that are made of multiple bits.
Bitwise negation is an operation where each bit of a binary number is negated so that zeros become ones and vice versa. The operator is ~.
Bitwise operations are a class of operations with the common feature that they manipulate individual bits. For example bitwise negation reverses each bit. Some operations take place between two binary values so that bits in the same position affect each other. These operations include and (&), or (|) and xor (^). There's also shift operations (<< and >>) where the bits of one binary number are shifted to the left or right N steps.
Byte is the size of one memory slot - typically 8 bits. It is the smallest unit of information that can be addressed from the computer's memory. The sizes of variable types are defined as bytes.
External code in C is placed in libraries from which they can be taken to use with the #include directive. C has its own standard libraries, and other libraries can also be included. However any non-standard libraries must be declared to the compiler. Typically a library is made of its source code file (.c) and header file (.h) which includes function prototypes etc.
Functions in C are more static than their Python counterparts. A function in C can only have ne return value and its type must be predefined. Likewise the types of all parameers must be defined. When a function is called, the values of arguments are copied into memory reserved for the function parameters. Therefore functions always handle values that are separate from the values handled by the coe that called them.
C variables are statically typed, which means their type is defined as the variable is introduced. In addition, C variables are tied to their memory area. The type of a variable cannot be changed.
Character is a single character, referred in C as char. It can be interpreted as an ASCII character but can also be used as an integer as it is the smallest integer that can be stored in memory. It's exactly 1 byte. A character is marked with single quotes, e.g. 'c'.
Code block is a group of code lines that are in the same context. For instance, in a conditional structure each condtion contains its own code block. Likewise the contents of a function are in their own code block. Code blocks can contain other code blocks. Python uses indentation to separate code blocks from each other. C uses curly braces to mark the beginning and end of a code block.
Comments are text in code files that are not part of the program. Each language has its own way of marking comments. Python uses the # character, C the more standard //. In C it's also possible to mark multiple lines as comments by placing them between /* and */.
A compiler is a program that transforms C source code into a binary file containing machine language instructions that can be executed by the computer's processor. The compiler also examines the source code and informs the user about any errors or potential issues in the code (warnings). The compiler's behavior can be altered with numerous flags.
Complement is a way to represent negative numbers, used typically in computers. The sign of a number is changed by flipping all its bits. In two's complement which is used in this course, 1 is added to the result after flipping.
Conditional statement is (usually) a line of code that defined a single condition, followed by a code block delimited by curly braces that is entered if the condition evaluates as true. Conditional statements are if statements that can also be present with the else keyword as else if. A set of conditional statements linked together by else keywords are called conditional structures.
Conditional structure is a control structure consisting of one or more conditional statements. Most contrl structures contain at least two branches: if and else. Between these two there can also be any number of else if statements. It is however also possible to have just a single if statement. Each branch in a conditional structure cotains executable code enclosed within a block. Only one branch of the structure is ever entered - with overlapping conditions the first one that matches is selected.
Control structures are code structures that somehow alter the program's control flow. Conditional structures and loops belong to this category. Exception handling can also be considered as a form of control structure.
Data structure is a comman name for collection that contain multiple values. In Python these include lists, tuples and dictionaries. In C the most common data structures are arrays and structs.
Python's way of treating variable values is called dynamic typing aka duck typing. The latter comes from the saying "if it swims like a duck, walks like a duck and quacks like a duck, it is a duck". In other words, the validity of a value is determined by its properties in a case-by-case fashion rather than its type.
An error message is given by the computer when something goes wrong while running or compiling a program. Typically it contains information about the problem that was encountered and its location in the source code.
An exception is what happens when a program encounters an error. Exceptions have type (e.g. TypeError) that can be used in exception handling within the program, and also as information when debugging. Typically exceptions also include textual description of the problem.
Flags are used when executing programs from the command line interface. Flags are options that define how the program behaves. Usually a flag is a single character prefixed with a single dash (e.g. -o) or a word (or multiple words connected with dashes) prefixed with two dashes (e.g. --system. Some flags are Boolean flags which means they are either on (if present) or off (if not present). Other flags take a parameter which is typically put after the flag separated either by a space or = character (e.g. -o hemulen.exe.
Floating point numbers are an approximation of decimal numbers that are used by computers. Due to their archicture computers aren't able to process real decimal numbers, so they use floats instead. Sometimes the imprecision of floats can cause rounding errors - this is good to keep in mind. In C there are two kinds of floating point numbers: float and double, where the latter has twice the number of bits.
Header files use the .h extension, and they contain the headers (function prototypes, type definitions etc.) for a .c file with the same name.
Headers in C are used to indicate what is in the code file. This includes things like function prototypes. Other typical content for headers are definition of types (structs etc.) and constants. Headers can be at the beginning of the code file, but more often - especially for libraries - they are in placed in a separate header (.h) file.
Hexadecimal numbers are base 16 numbers that are used particularly to represent memory addresses and the binary contents of memory. A hexadecimal number is typically prefixed with 0x. They use the letters A-F to represent digits 10 to 15. Hexadecimals are used because each digit represents exactly 4 bits which makes transformation to binary and back easy.
In Python objects were categorized into mutable and immutable values. An immutable value cannot have its contents changed - any operations that seemingly alter the object actually create an altered copy in a new memory location. For instance strings are immutable in Python. In C this categorization is not needed because the relationship of variables and memory is tighter - the same variable addresses the same area of memory for the duration of its existence.
When a variable is given its initial value in code, the process is called initialization. A typical example is the initialization of a number to zero. Initialization can be done alongside with introduction: int counter = 0; or separately. If a variable has not been initialized, its content is whatever was left there by the previous owner of the memory area.
Instruction set defines what instructions the processor is capable of. These instructions form the machine language of the processor architecture.
Integers themselves are probably familiar at this point. However in C there's many kinds of integers. Integer types are distinguished by their size in bits and whether they are signed or not. As a given number of bits can represent up to (2 ^ n) different integers, the maximum value for a signed integer is (2 * (n - 1))
Python interpreter is a program that transforms Python code into machine language instructions at runtime.
The moment a variable's existence is announed for the first is called introduction. When introduced, a variable's type and name must be defined, e.g. int number;. When a variable is introduced, memory is reserved for it even though nothing is written there yet - whatever was in the memory previously is still there. For this reason it's often a good idea to initialize variables when introducing them.
Iteroitava objekti on sellainen, jonka voi antaa silmukalle läpikäytäväksi (Pythonissa for-silmukalle). Tähän joukkoon kuuluvat yleisimpinä listat, merkkijonot ja generaattorit. C:ssä ei ole silmukkaa, joka vastaisi Pythonin for-silmukan toimintaa, joten taulukoiden yms. läpikäynti tehdään indeksiä kasvattavilla silmukoilla.
Keywords are words in programming languages that have been reserved. Good text editors generally use a different formatting for keywords (e.g. bold). Usually keywords are protected and their names cannot be used for variables. Typical keywords include if and else that are used in control structures. In a way keywords are part of the programming language's grammar.
A library is typically a toolbox of functions around a single purpose. Libraries are taken to use with the include directive. If a library is not part of the C standard library, its use must also be told to the compiler.
Logical operation refers to Boole's algebra, dealing with truth values. Typical logical operations are not, and, or which are often used in conditional statements. C also uses bitwise logical operations that work in the same way but affect each bit separately.
Machine language is made of instructions understood by the processor. Machine language is often called Assembly and it is the lowest level where it's reasonable for humans to give instructions to computers. Machine language is used at the latter part of this course - students taking the introduction part do not need to learn it.
Macro is an alias that defines a certain keyword to be replaced by a piece of code. When used well, macros can create more readable code. However, often the opposite is true. Using macros is not recommended in this course, you should just be able to recognize one when you see it.
In C the main function is the starting point when the program is run. The command line arguments of the program are passed on to the main function (although they do not have to be received), and its return value type is int. At its shortest a main function can defined as int main().
When programs are run, all their data is stored in the computer's memory. The memory consists of memory slots with an address and contents. All slots are of equal size - if an instance of data is larger, a continuous area of multiple memory slots is reserved.
Method is a function that belongs to an object, often used by the object to manipulate itself. When calling a method, the object is put before the method: values.sort().
Object is common terminology in Python. Everything in Python is treated as objects - this means that everything can be referenced by a variable (e.g. you can use a variable to refer to a function). Objects are typically used in object-oriented languages. C is not one.
Optimization means improving the performance of code, typically by reducing the time it takes to run the code or its memory usage. The most important thing to understand about opimization is that it should not be done unless it's needed. Optimization should only be considered once the code is running too slowly or doesn't fit into memory. Optimization should also not be done blindly. It's important to profile the code and only optimize the parts that are most wasteful.
A parameter is a variable defined alongside with a function. Parameters receive the values of the function's arguments when it's called. This differentation between parameters and arguments is not always used, sometimes both ends of the value transfer are called arguments.
Placeholders are used in string formatting to mark a place where a value from e.g. a variable will be placed. In Python we used curly braces to mark formatting placeholders. In C the % character is used which is followed by definitions, where the type of the value is mandatory. For instance "%c" can only receive a char type variable.
Pointers in C are special variables. A pointer contains a memory address of the memory location where the actual data value is located. In a sense they work like Python variables. A variable can be defined as a pointer by postfixing its type with * when it's being introduced, e.g. int* value_ptr; creates a pointer to an integer. The contents of the memory address can be fetched by prefixing the variable name with * (e.g. *value_ptr. On the other hand, the address of a memory adress can be fetched by prefixing a variable name with &, (e.g. &value.
The C precompiler is an apparatus that goes through all the precompiler directives in the code before the program is actually compiled. These directives include statements which add the source code of the included libraries into the program, and define directives that can define constant values (aliases) and macros.
Directives are instructions that are addressed at the precompiler. They are executed and removed from the code before the actual compilation. Directives start with the # character. The most common one is include which takes a library into use. Another common one is define, which is used e.g. to create constant values.
Prototype defines a function's signature - the type of its return value, its name and all the arguments. A prototype is separate from the actual function definition. It's just a promise that the function that matches the prototype will be found in the code file. Prototypes are introduced at the beginning of the file or in a separate header file. In common cases the prototype definition is the same as the line that actually starts the function introduction.
Interactive interpreter or Python console is a program where users can write Python code lines. It's called interactive because each code line is executed after its been fully written, and the interpreter shows the return value (if any).
The format method of string in Python is a powerful way to include variable values into printable text. The string can use placeholders to indicate where the format method's arguments are placed.
Python functions can have optional parameters that have a given default value. In Python the values of arguments in a function call are transferred to function parameters through reference, which means that the values are the same even though they may have different names. Python functions can have multiple return values.
In Python the import statement is used for bringing in modules/libraries - either built-in ones, thrid party modules or other parts of the same application. In Python the names from the imported module's namespace are accessible through the module name (e.g. math.sin). In C libraries are taken to use with include, and unlike Python import it brings the library's namespace into the program's global namespace.
Python lists were discovered to be extremely effective tools in Elementary Programming. A Python list is an ordered collection of values. Its size is dynamic (i.e. can be changed during execution) and it can include any values - even mixed types. Lists can also include other lists etc.
In Python main program is the part of code that is executed when the program is started. Usually the main program is at the end of the code file and most of the time under if __name__ == "__main__": if statement. In C there is no main program as such, code execution starts with the main function instead.
In Python a variable is a reference to a value, a connection between the variable's name in code and the actual data in memory. In Python variables have no type but their values do. The validity of a value is tested case by case when code is executed. In these ways they are different from C variables, and in truth Python variables are closer to C pointers.
Pythonin for-silmukka vastaa toiminnaltaan useimmissa kielissä olevaa foreach-silmukkaa. Se käy läpi sekvenssin -esim. listan - jäsen kerrallaan, ottaen kulloinkin käsittelyssä olevan jäsenen talteen silmukkamuuttujaan. Silmukka loppuu, kun iteroitava sekvenssi päättyy.
Pääfunktio on C:ssä ohjelman aloituspiste ja se korvaa Pythonista tutun pääohjelman. Oletuksena pääfunktion nimi on main ja se määritellään yksinkertaisimmillaan int main().
Resource referes to the processing power, memory, peripheral devices etc. that are availlable in the device. It includes all the limitations within which programs can be executed and therefore defines what is possible with program code. On a desktop PC resources are - for a programmer student - almost limitless, but on embedded devices resources are much more scarce.
Return value is what a function returns when its execution ends. In C functions can only have one return value, while in Python there can be multiple. When reading code, return value can be understood as something that replaces the function call after the function has been executed.
A statement is a generic name for a single executable set of instructions - usually one line of code.
C uses static typing This means that the type of variables is defined as they are created, and values of different types cannot be assigned to them. The validity of a value is determined by its type (usually done by the compiler). Python on the other hand uses dynamic typing aka.duck typing.
In Python all text is handled as strings and it has no type for single characters. However in C there are no strings at all - there's only character arrays. A character array can be defined like a string however, e.g. char animal[7] = "donkey"; where the number is the size of the array + 1. The +1 is neede because the string must have space for the null terminator '\0' which is automatically added to the end of the "string".
Syntax is the grammar of a programming language. If a text file does not follow the syntax of code, it cannot be executed as code, or in the case of C, it cannot be compiled.
Terminal, command line interface, command line prompt etc. are different names to the text-based interface of the operating system. In Windows you can start the command line prompt by typing md to the Run... window (Win+R). Command line is used to give text-based commands to the operating system.
The data in a computer's memory is just bits, but variables have type. Type defines how the bits in memory should be interpreted. It also defines how many bits are required to store a value of the type. Types are for instance int, float and char.
Typecast is an operation where a variable is transformed to another type. In the elementary course this was primarily done with int and float functions. In C typecast is marked a bit differently: floating = (float) integer}. It's also noteworthy that the result must be stored in a variable that is the proper type. it is not possible to change the type of an existing variable.
Unsigned integer is a an integer type where all values are interpreted as positive. Since sign bit is not needed, unsigned integers can represent twice as large numbers as signed integers of the same size. An integer can be introduced as unsigned by using the unsigend keyword, e.g. unsigned int counter;.
In the elementary programming course we used the term value to refer to all kinds of values handled by programs be it variables, statement results or anything. In short, a value is data in the computer's memory that can be referenced by variables. In C the relationship between a variable and its value is tighter as variables are strictly tied to the memory area where its value is stored.
A warning is a notification that while executing or - in this course particularly - compiling it, something suspicious was encountered. The program may still work, but parts of it may exhibit incorrect behavior. In general all warnings should be fixed to make the program stable.
One way to print stuff in C is the printf function, which closely resembles Python's print function. It is given a printable string along with values that will be formatted into the string if placeholders are used. Unlike Python, C's printf doesn't automatically add a newline at the end. Therefore adding \n at the end is usually needed.
Out of loops, while is based on repetition through checking a condition - the code block inside the loop is repeated until the loop's condition is false. The condition is defined similarly to conditional statements, e.g. while (sum < 21).