progweek2 Flashcards

1
Q

the program starts to be executed with which function?

A

main()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Everytime program control encounters a function name, this function
will be _

A

called or invoked.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

explain: The arguments are passed ”called-by-value”.

A

This means that each argument is evaluated, and the value is used locally for the corresponding formal parameter. The value is copied into the local variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If a variable is passed to a function by value, the original value of the
variable will (or will not) be changed?

A

not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is scope?

A

It refers to the area where a function or variable is visible and
accessible to other codes.

”Identifiers are accessible only within the block in which they are
declared”

Be aware that the same identifier can be used in different declarations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Parallel blocks are _

A

blocks defined at the same level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

text files:

A

It is a file that contains ASCII characters, used to store a stream of
characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

key points of text files:

1
2
3
4

A
  1. Text files have no format, they are plain characters,
    whitespaces and line breaks.
  2. Each line in a text file ends with \n
  3. Example are files with .txt extension.
  4. They are a general and standard type to share information since they can be read or written by any text editor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The basic file operations that we can perform in C are:

A

Creating a new file

Opening an existing file

Reading from a file

Writing to a file

Moving to a specific location in a file

Closing a file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Creating a new file;

A

fopen() in mode ”a”/”a+” or ”w”/”w+”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Opening an existing file;

A

fopen()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Reading from a file;

A

fscanf() or fgets()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Writing to a file;

A

fprintf() or fputs()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Moving to a specific location in a file;

A

fseek()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Closing a file;

A

fclose()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A file pointer is

A

a reference to a
particular position in the opened file.
It is used in file handling to perform all file operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In C, we make use of the _ macro to declare the file pointer. The
macro is already define inside the _ header file.

A

FILE

stdio.h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

calloc and malloc in which library?

A

stdlib.h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

CPU :

A

(Central Processing Unit): The brain of the computer where most calculations take place

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

ALU :

A

(Arithmetic Logic Unit): Performs arithmetic and logic operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Control Unit:

A

Directs operations within the CPU, coordinating how data moves through it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

General Registers:

A

Small storage locations within the CPU that hold data temporarily during execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Memory:

A

Stores data and instructions that the CPU can quickly access. It is typically volatile, meaning it loses its contents when power is turned off.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Disc:

A

Refers to the storage devices like hard drives or SSDs that provide non-volatile storage, meaning they retain data when powered off.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

MMU :

A

(Memory Management Unit): A hardware component responsible for handling virtual and physical address translations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

BUS:

A

A communication system that transfers data between components inside a computer, or between computers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

what are the Other I/O Devices:

A

Monitor
Keyboard
Mouse
Printer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

physical memory:

A

any physical support that can be
used to store data. The physical memory of modern computer is organized
in a hierarchy (from fast-small to slow-big).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Registers:

A

Is space that is on the CPU and
is the working memory that allows the
processor to do basic operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Cache(s):

A

Is on the same chip of the CPU
or very close to it, and is therefore usually
very small but also very fast.

31
Q

Primary Memory (RAM):

A

Is on a
separate component, medium size, slower
than cache memory.

32
Q

Secondary Memory (Disks):

A

Your hard
drive, it is usually very large, but also much
slower than cache and RAM.

33
Q

Instead of dealing with the physical memory
programmers work on _. This means that __.

A

virtual memory

they can assume that there is only one memory unit consisting of an array of contiguous memory cells as big as the programs need (max 4 GB for 32-bit systems).

34
Q

Stack:

A

Portion of memory managed
by the runtime support of C.

35
Q

Heap:

A

Portion of memory managed
by the programmer.

36
Q

Static:

A

Portion of memory that
contains external (global) variables,
the code, constant values and any
static data.

37
Q

Runtime support :

A

is a collection of system software services that enable the execution of programs, managing necessary tasks like memory allocation and input/output operations behind the scenes.

38
Q

Stacks :

A

are arrays of data managed with a LIFO (Last in, first out) policy. The stack is where all the local variables of our program are stored.

39
Q

When we call a function in C:

  1. The _ of the CPU and other
    information needed to
    restore the current state of the
    program is pushed.
  2. The _ is pushed.
  3. The _ are pushed and the values
    of the actual parameters are
    copied (pass-by-value).
  4. Then _ are pushed.
  5. When we exit the function all the previous information is _.
  6. This information is usually called _.
A
  1. current state
  2. address of where the return value should be stored
  3. formal parameters
  4. local variables
  5. popped and
    used to restore the correct status of the caller
  6. activation record of the function
40
Q

Pointers are :

A

variables that store the memory addresses of other variables, allowing direct access and manipulation of the memory allocated to those variables in a C program.

41
Q

If x is a variable then &x denotes _ of x.

A

the address

42
Q

If x is of type T , then &x is of type _, e.g., if x is an integer then
&x is of type _.

A

T *

int* integer pointer

43
Q

One can therefore declare variables that are pointers to a type, e.g.,
int * p; declares _. We can therefore initialize it using _

A

a pointer to an integer

p = &x

44
Q

To access the content of the cell whose address is p we can use the __
operator, i.e., if x is 1 and p is &x then _ is 1.

A

*

*p

45
Q

_ is a special value that is used for empty pointers (pointers to
nothing).

A

NULL

46
Q

Pointers allow to implement a different type of parameter passing
called _.

A

call-by-reference

47
Q

The idea is that instead of passing the value to a function we pass
__. In this way we have direct access to the cell
containing the actual parameter and can modify its content.

A

a pointer to that value

48
Q

Arrays :

A

are the simplest way of grouping data. An array is a sequence of
homogeneous data that can be accessed using their position.

49
Q

The size of the array should be known at _.

A

compile time

50
Q

Arrays are actually _.

A

addresses to the first element of the sequence

51
Q

A is :

A

the address of A[0]

52
Q

*A is just another way of writing _

A

A[0]

53
Q

p + 1 is evaluated to the arithmetic operation _

A

p + sizeof(T )

54
Q

p − 1 is evaluated to the arithmetic operation _

A

p − sizeof(T )

55
Q

A[n] becomes _

A

∗ (A + n)

56
Q

For arrays declared as T A[N], A is _. So, we cannot modify __, e.g., doing A + +, this also means that _.

A

not a variable (just a name)

A

&A = A

57
Q

But remember that parameter passing is still _ for the array itself

A

by-value

58
Q

arrays issues:

A

We cannot return arrays in functions.

We cannot have large arrays.

The size of the array must be known at compile time.

59
Q

The solution to all three problems of arrays is to _.

A

use dynamic
allocation of memory

60
Q

characteristics oh the heap:

A

The heap is much bigger than the stack.

Values on the heap do not disappear unless we explicitly free the
memory.

Allocating portions of the heap at run time is not problematic since it does not interfere with the working of functions.

61
Q

The _ offers functions to manage the heap

A

standard library (stdlib.h)

62
Q

calloc

A

(n, size): allocates n many contiguous cells of memory each of size size and initializes all bits to 0

63
Q

malloc

A

(n*size): allocates n many contiguous cells of memory of size
size in total.

64
Q

free(p):

A

takes a pointer to a piece of memory in the heap and
deallocates the pointed space.

65
Q

In C _ are used to implement strings. A string is _

A

arrays

just an array of
characters.

66
Q

char *s=”this is a string.” → __

char s[ ]= “this is a string” == _

A

immutable, like a constant

char A[ ]={‘t’,’h’,’i’,’s’,…} !!!

67
Q

Note that every string must end with a “hidden” special character:

A

′\0′ !!! pas oublier les ‘ ‘ !!!!

68
Q

any constant string is
_.

A

a constant array of characters whose elements cannot be modified

69
Q

The standard library offers many functions that can help deal with strings.
To use them include _.

A

string.h

70
Q

How to concatenate the string in
s1 and s2 and put the result in s1?

The programmer has to ensure
that _

A

strcat(char ∗ s1, const char ∗ s2)

s1 has enough space to contain the concatenation

71
Q

__: compares s1 and s2
and returns an integer. The return value is :

<0 if s1 is __ than s2,

0 if _

a number > 0 if s1 is __ than s2

A

strcmp(const char ∗ s1, const char ∗ s2)

lexicographically smaller

the two strings are equal

lexicographically bigger

72
Q

__: the characters of s2 are
copied in s1.

A

strcpy(char ∗ s1, const char ∗ s2)

73
Q

__: returns the number of characters in s.

A

strlen(const char * s)

74
Q

Important: If you need to pass a matrix as a parameter, the formal
parameter must include the size of the number of _.

A

columns