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

Control Structures in C

Learning Objectives: This material explains how to implement and control the logical functionality of a program in C using control structures. Additionally, it emphasizes the importance of making the code visually clear.
Control structures in C are as follows:
This part of the lecture material is likely the most straightforward and easiest to grasp in the course, as there are no significant differences in the behavior of these structures in C compared to other programming languages.

Truth Values

First, it is essential to understand what is considered true in C, i.e., how the truth value of a program statement is determined. In C, it is defined numerically as follows:
Example. After the assignment, the value of the variable would be interpreted as true here int8_t is_warm = -25;.
int8_t temperature_sensor_reading = -25;

if (temperature_sensor_reading) {
    printf("The sensor is active, temperature is being measured.\n");
} else {
    printf("The sensor is inactive or malfunctioning.\n");
}

Logical Operators

The logical operators we can use to evaluate the truth values of expressions in C are as follows:
Examples.
uint8_t variable1 = 0;
uint8_t variable2 = 5;
int8_t variable3 = -27;

int8_t result1 = !variable1; // true
int8_t result2 = variable1 && variable2; // false
int8_t result3 = variable2 && variable3; // true
In C, logical operations && (logical AND) and || (logical OR) use short-circuit evaluation. This means that the evaluation of expressions stops as soon as the result is determined.
For && (logical AND), if the first operand evaluates to false (0), the entire expression is false, so the second operand is not evaluated.
For || (logical OR), if the first operand evaluates to true (non-zero), the entire expression is true, so the second operand is not evaluated.

Comparison Operators

C's comparison operators are numerical:
Remember from earlier material that in C, characters are also treated as numbers according to the ASCII encoding. So whenever a condition is numerically true, the code block of the statement will be executed.
In C, multiple conditions or comparisons cannot be combined into a single condition; instead, comparisons must be separated and combined with a logical operator. For example:
// Python: ('a' <= character <= 'z')
if ((character >= 'a') && (character <= 'z')) 
   {
   ...
   }
Note! To avoid bugs, remember to use parentheses around different expressions in comparison and conditional structures to ensure that your intention is directly reflected in the code. Otherwise, you must be very familiar with the order of operations of C operators!
Note! Another common programming mistake is using the assignment operator = instead of the comparison operator ==. Similarly, the bitwise operator & can be confused with the logical AND operator &&. The compiler will usually warn about these.

Conditional Structures

There are two conditional structures in C. The traditional if-else structure and the multi-part conditional structure switch.

If-else if-else Discussion

C's conditional statements include the same if, else if, and else branches found in other programming languages, and they function the same way. The branches are tested in the given order, and the first one that evaluates to true will execute its associated code block, and the structure will exit. Conditional expressions are placed inside parentheses ( ) .
if (number < 10) {
    printf("The number is less than 10");
}
else if (number < 100) {
    printf("The number is less than 100");
}
else if (number < 1000) {
    printf("The number is less than 1000");
}
else {
    printf("The number is equal to or greater than 1000");
}
Sometimes you might see C control structures implemented without code blocks. This is perfectly valid C code, in which case only the statement following the condition is executed if the condition is true.
if (number < 100)
    printf("The number is less than 100");
Note! If you want to execute multiple statements when a condition is true, you must use a block, so it's good practice to always use curly braces from the very beginning!

Switch Flips the Switch

C also has a multi-part conditional structure called switch, which tests whether a variable's value matches one of the given integer constants. The reasoning is that switch might be clearer when checking constant values compared to if-else structures.
The syntax of the switch statement is as follows. Note that, unlike other structures, this statement does not use block markers but instead relies on the break; statement to indicate where a block ends.
switch (variable) {
   case CONSTANT1:        
      statement;
      statement;
      break;
   case CONSTANT2:
      statement;
      statement;
      break;
   default:
      statement;
      statement;
      break;
}
The switch structure is processed from top to bottom, comparing the variable's value to the constants. If a match is found, the corresponding code block is executed until a break statement is encountered. After that, the structure exits. The default block is optional and is executed only if none of the other conditions match.
If the break is omitted, execution will fall through from one block to the next until a break is encountered or the structure ends. This can be useful if you know what you're doing, as it allows you to handle multiple conditions with the same block.
In fact, the switch statements could be implemented using an equivalent if-else structure:
switch(choice) {		if (choice == 'p') {  
    case 'p':				length();
        length();		} else if (choice == 'm') {
        break;				mass();
    case 'm':			} else if (choice == 't') {
        mass();			volume();
        break;			} else if (choice == 'l') {
    case 't':				temperature();
        volume();		} else {
        break;				error();
    case 'l':			}
        temperature();
        break;
    default:
        error();
        break;
}
Here, the evaluation of conditions flows downward in the same way as in the if-else structure. So, in a way, the switch structure is unnecessary, but it is an easy-to-read way to implement constant value checks with many parallel options. Additionally, you'll undoubtedly encounter this structure in code written by others, so it's good to know what it's all about.

Loop Structures

In C, we can of course perform both counted and conditional looping.

Counting loops

Counting looping in C is implemented using the for statement. The statement in C is slightly more demanding for the coder than in other languages.
The syntax is as follows.
for (initialization statement; condition statement; increment statement) {
    statement;
    statement;
}
Now, to help with the for loop, we need a loop variable that indicates the iteration in the condition statement.
  1. In the initialization statement, we give the loop variable its starting value.
  2. In the condition statement, we test the value of the loop variable.
    1. If the condition is met, the code block is executed.
    2. If the condition is not met, the loop is exited.
  3. The increment statement defines how the loop variable changes for the next iteration, i.e., for the next condition test.
Examples.
uint8_t i;                  uint8_t i;                  uint8_t i;

for (i=0; i < 10; i++) {    for (i=10; i > 0; i--) {    for (i=0; i <= 20; i+=2) {
   do_something();             do_something();             do_something();
}                           }                           }
In the first case, the value of the loop variable increases by one, in the second case it decreases by one, and in the third case it increases by two.
As can be seen, various comparisons can be made in the condition statement of the for loop. And the increment statement can take different forms... in fact, (almost) all C operators and even function calls whose return values are tested can be used there!
And to make the for loop not too simple, we can initialize multiple loop variables within it, separated by commas. This allows us to conveniently have multiple auxiliary variables within the code block...
int i,j;

for (i=0, j=10; i < 10; i++, j--) {
   do_something(i,j); 
}							

Conditional Looping

Conditional looping in C can be implemented in two ways.

Test First, Then Execute

In the while statement, the code block is executed in the loop as long as the condition is true. Therefore, the while loop is best suited for situations where the number of repetitions is not known in advance.
The syntax is very straightforward.
while (condition) {
    statement;
    statement;
}
A simple example. On the side, the equivalent for statement for the C compiler.
uint8_t i=0;            uint8_t i=0;

while (i < 10) {        for (i=0; i < 10; i++) { 
   do_something();         do_something();
   i++;                 }
}
Sometimes the for statement may be stylistically better because it keeps the loop control statements close to each other structurally.

Execute First, Then Test

Again, the do-while structure executes its code block first and then tests the condition statement afterward. If the condition is false, the loop is exited. This structure can sometimes be a stylistically better solution than the while structure, for example, if a repetitive operation on the variables in the condition needs to be performed before testing them.
The syntax is not particularly special.
do {
   statement;
   statement;
} while (condition);

Let's Take a Break

Related to control structures, we can also control the flow of code within a block using the commands break and continue.
Now, with the break command, we can jump out of any block even in the middle of its execution. For example:
while (x > 0) {
    if (x == SPECIAL_CONSTANT) {       
        break;
    }
    x = do_something();
} 
Then continue jumps to the next iteration of the loop, but of course, it executes the increment statement first. For example, the function do_something is not executed if the equality condition in the if statement is met.
for (x=0; x < 100; x++) {
    if (x == SPECIAL_CONSTANT) {
       continue;
    }    
    do_something();
}

Infinite Loop

One special case in the use of loop structures is very common in embedded systems programming.
Sometimes, the functionality of an embedded program is implemented inside a single infinite loop, which is part of the program's main function. As noted earlier, a C program runs until this function ends. So, conveniently (well, not really...), in an embedded program, waiting for input is done by running an infinite loop. This type of solution is called a superloop structure and might be familiar from Arduino programming, for example.
int main() {         
   
   while (1) {    
      if (check_input()) {
         do_something();
      }
    }                  
} 
Input to the program can be obtained by polling, as in the example above with the check_input function, or by interrupts. Well, more on that in future material...
Although this solution is simple, it is not technically good from a programming perspective. For example, because the condition testing is sequential and not parallel. Secondly, most of the execution time, the program tests statements that do not actually occur from the device's perspective. If the device has the resources to run an operating system, it is a better solution to let it decide when each functionality of the program is executed. The operating system often also manages the device's power consumption programmatically, which can be more difficult to achieve in a superloop structure.
We will return to this when learning to program our Hardware device.

A Word on Coding Style

Let's further justify why it's a good idea to use curly braces. The following code snippet is valid C, but not very readable. For example, now if the programmer succumbs to Python-style indentation, which if statement does the else structure belong to?
if (n > 0) 
   m = n + 10;
   if (n > 10)
      m = n;
else 
   n += 10;
From the example, we also notice how difficult it can be to read nested if-else structures. Sometimes a beginner programmer creates overly long if-else structures (which on paper will max out the print quota). Later, finding a bug in such a program is a really thankless task and can actually take hours of time.
In this course, we do not write such code, but we know how to divide our program into clear blocks and functions that are at most one screen in length.

In Conclusion

With the looping skills learned from Python, you can handle everything in this course, as long as you learn the syntax and special cases. New concepts, such as do-while loops and switch structures, are useful at times.
Different C language standards support slightly different C code regarding code blocks and control structures. For example, in the old C89 standard, variables could not be declared in the initialization structure of a for loop but had to be declared earlier in the code. However, in current standards, this is possible.
for (int a = 0; a < 10; a++) {
}
Since in C, the appearance of code has little significance, we can write for loops, for example, like this. The functionality of the program could not really be easily seen from the code...
Final greetings from the assistants: In this course, we save everyone's time and effort by writing our own code in a modular fashion using functions and code blocks that are clearly readable with proper indentation, parentheses, and curly braces.
?
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).