| Fråga   | Svar   | 
        
        |  börja lära sig How can we determine the specific size of a particular data type?  |  |   You need to use sizeof operator. It returns the size in bytes of its operand. you can use printf(“Size od int: %zu bytes\n”, sizeof(int));  |  |  | 
|  börja lära sig How do we put the header files of other modules or libraries into the source file od the program?  |  |   we use #include “header_file_name. h” if the header file is in the same directory as source file. From standard library we can include like #include <stdio. h>  |  |  | 
|  börja lära sig How do we approach data fields of the composite data type (struct) in C?  |  |   We use the dot. operator It allows to access individual members of the struct. Such as struct Person {char name[50]; int age;}; int main() {person1. age = 30;} We can also use pointers to structs in that case use arrow operator -> instead dot  |  |  | 
|  börja lära sig Describe how the function int doit(int r) is called and how are the data passed to it.  |  |   When function is called the program execution jumps to the functions definition, executes the statements inside function and the returns control to point in the program immedietaly following function call  |  |  | 
|  börja lära sig How do you dynamically allocate memory for storing a sequence of 20 values of the data type int?  |  |   We use malloc function from library <stdlib. h>. We declare a pointer to an integer int *sequence to hold the address. We use malloc for an areat of 20 integers sequence = (int *) malloc(20 * sizeof(int)); Then we check if memory allocation was succesful  |  |  | 
|  börja lära sig How do you increase a dynamic array to save ten more items?  |  |   Allocate new memory using realloc and copy existing data from old array to the new. Then free memory and update the pointer  |  |  | 
|  börja lära sig What is the NULL identifier?  |  |   Its a null pointer constant typically defined as an integer constant zero. Its purpose is to indicate that a pointer does not point to any memory location. It usually indicates the end of a list. For example when alloc of memory fail Null returned  |  |  | 
|  börja lära sig How are text strings represented in C?  |  |   For that we use arrays of characters, terminated by a null character ‘\0’ Those are C-strings. char str[6] = {‘h’, ’e’, ’j’} or using string literals char str[] = “Hej”; In this case compiler add the null chracter automatically at the end of the string  |  |  | 
|  börja lära sig What represents the void type?  |  |   Its a special keyword used to indicate the absence of type. It can be used in several contexts: Function does not return any value void name(parameters), Function doesnt accept parameters void name(void), generic pointers can point to any datatype void *p  |  |  | 
|  börja lära sig Explain the difference between the variable and the pointer to a variable.  |  |   holds values directly vs hold memory addresses; accesed directly by names vs dereferenced; modifying changes the value vs memory address; pointers allow dynamkc memory alloc but require dereferencing  |  |  | 
|  börja lära sig What are the characters used in C for output control?  |  |   newline character \n; horizontal tab character \t; Backspace character \b; carriage return character \r  |  |  | 
|  börja lära sig How to get a pointer to a variable defined as double d = 12.3;  |  |   Declare a pointer of type double * and assign the address of the variable d to it using the address-of operator %. double d = 12.3; double *ptr; ptr = &d  |  |  | 
|  börja lära sig How is the pointer and array [] different?  |  |   dynamic memory vs static; dont know size and length vs arrays know that; can be incremented and decremented vs not; need to be explicitly initialized to point to address vs can be initialized with initial values  |  |  | 
|  börja lära sig What is the difference between a pointer to a constant and a constant pointer?  |  |   A pointer to a constant (const int *ptr) allows modification of the pointer itself but not the value it points to. A constant pointer (int *const ptr) allows modification of the value it points to but not the pointer itself. Both concepts are useful  |  |  | 
|  börja lära sig Define a variable length array s of the size n, which is provided as a command line argument?  |  |   int main(int argc, char *argv[]) {int n = atoi(argv[1]); int *s = (int *) malloc(n * sizeof(int));  |  |  | 
|  börja lära sig Describe briefly the struct type used in C.  |  |   It allows to group together one or more variables of diff data types under single name. example: struct Person {char name[50]; int age;};  |  |  | 
|  börja lära sig What C compilers do you know?  |  |   GCC the most widely used available on multiple platforms; Clang excellent diagnostics known for fast compilation speed  |  |  | 
|  börja lära sig Describe the process of creating an executable program from the C source files.  |  |   Writing source code; compilation; each source file produces object file; linking libraries; executing program  |  |  | 
|  börja lära sig Explain the difference between the variable and the pointer to a variable?  |  |   While variables store values directly and are accesed by their names, pointers store memory addresses of variables and allow indirect access to their values. Pointers provide additional flexibility and functionality especially in terms of memory mamagemen  |  |  | 
|  börja lära sig Does const in the variable definition guarantee that it cannot change?  |  |   While const provides a level of immutability and helps prevent unintended modifications to variables, it does not offer complete protecion against all. It can be changed with pointers indirectly, but it may make program behavior unpredictable  |  |  | 
|  börja lära sig For what is the keyboard ‚do’ used  |  |   Part of the do while loop structure it allows to repeatedly execute a block of cide whjle a specified condition is true, with the condition checked after each iteration. do {things} while (count < 5)  |  |  | 
|  börja lära sig For what is the keyword ‚while’ used?  |  |   while (count < 5) {things}  |  |  | 
|  börja lära sig For what is the keyword ‚for’ used?  |  |   For loop, initalization, condition and update. for (int i = 0; i < 5; i++) {things}  |  |  | 
| börja lära sig |  |   conditional statements evaluated true or false  |  |  | 
| börja lära sig |  |   various possible execution paths based on the value of an expression. switch (option) {case 1: things case 2: things default: things}  |  |  | 
| börja lära sig |  |   Used to create multi way branch statement which allows you to select one of many code blocks to be executed based on the value of an expression  |  |  | 
| börja lära sig |  |   used to exit from a loop or switch statement prematurely terminates the innermost liop kr switch in which is contained  |  |  | 
|  börja lära sig How do you create a pointer to a variable such ad int?  |  |   declare the pointer assign the address example: int num = 10; int *ptr; ptr = #  |  |  | 
|  börja lära sig What is the program return value that indicates a succesful execution and why?  |  |   Its typically zero. Due to clarity, convention, compatibility with shell scripts, error reporting, and consistency  |  |  | 
|  börja lära sig How do you dynamically allocate memory in C.  |  |   You can use malloc(), calloc(), or realloc() which are part of stdlib.h. You also need to free it after all  |  |  | 
|  börja lära sig How do you release dynamically allocated memory in c  |  |   its released using free() function. always do it to prevent memory leaks.  |  |  | 
|  börja lära sig Define the diagonal matrix 3x3 as a 2D int array  |  |   int diaginal[3][3] = {{1,0,0},{0,1,0},{0,0,1}};  |  |  | 
|  börja lära sig Whats a difference between a thread and a process  |  |   share resources vs isolated; communicate through shared memory vs require ipc mechanisms; lower creation and context switching of threads; failure affect other threads vs does not  |  |  | 
|  börja lära sig What is critical section?  |  |   part of programs code that must be executed by only one process or thread at a time. Its a region of code where shared resources are accesed and manipulated and concurrent acess by multiple process or threads could lead to incorrect results  |  |  |