Exam prep Flashcards

1
Q

What are stack and heap in a program, and how are variables stored in them?

A

Stack is a region of memory used for temporary storage of variables in a program, where variables are pushed and popped in a Last In, First Out (LIFO) manner.

Heap, on the other hand, is a region of memory used for dynamic memory allocation, where variables are stored in a more flexible manner.

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

What does it mean that a variable is placed in a memory on the stack?

A

When a variable is placed in a memory on the stack, it means that the memory space for that variable is reserved during the compilation time, and the variable is automatically deallocated when it goes out of scope.

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

What does it mean that a variable is planed in a memory on the heap?

A

When a variable is placed in a memory on the heap, it means that the memory space for that variable is allocated during runtime, and the variable remains in memory until it is explicitly deallocated by the program.

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

How do we define and allocate memory for a variable of type int on the stack?

A

To define and allocate memory for a variable of type int on the stack, we can simply declare the variable within a function. For example: int x = 10;

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

How do we define and allocate memory for a variable of type in on the heap?

A

To define and allocate memory for a variable of type int on the heap, we need to use dynamic memory allocation functions such as malloc() or new. For example: int* x = new int(10);

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

What can we do with the allocated memory on the heap, that we cannot do with the memory on the stack?

A

We can perform dynamic memory allocation and deallocation on the heap, which allows us to allocate memory of arbitrary size during runtime. This is not possible on the stack, where memory allocation is fixed during compilation time.

Additionally, the memory allocated on the heap can be accessed from different parts of the program, whereas the memory on the stack is only accessible within the scope it was declared in.

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

int *x();

a) x is a pointer to a function that returns an int
b) x is a function that returns a pointer to an int
c) x is a variable of type int
d) x is a pointer to a pointer to a function that returns a variable of type int

A

b) x is a function that returns a pointer to an int

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

int ( * x [] ) ();
a) x is an array of pointers to functions that return int
b) x is a function which takes as an argument an array of pointers to variables of type int
c) x is a function that takes an array as an argument and returns a pointer to int
d) x is a pointer to a function that takes as an argument an array of integers

A

a) x is an array of pointers to functions that return int

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

char * ( * ( * x [ ] [8] ) ( ) ) [ ];

a) x is array of array of 8 pointers to a pointer to functions returning pointer to array of pointer to char

b) x is an array of 8 pointers to pointer to function returning pointer to array of pointer to char

c) x is array of array of 8 pointers to a function returning pointer to array of pointer to char

d) x is a function that takes as input an array of 8 pointers to pointer to an array and returns a pointer to array of pointer to char

A

a) x is array of array of 8 pointers to a pointer to functions returning pointer to array of pointer to char.

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

int ( * ( * x ) [ ] ) ( );

a) x is an array of pointers to functions that take no arguments and return pointers to int

b) x is a function that takes as argument an array of pointers to functions and return a pointer to int

c) x is a function that takes as an argument a pointer to an array of pointers and returns a pointer to int

d) x is a pointer to an array of pointers to functions returning an int

A

d) x is a pointer to an array of pointers to functions returning an int

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

char ( * * x ( ) ) [20];

a) x is an array of pointers to functions returning pointers to functions returning pointers to
char
b) x is a pointer to a function returning a pointer to an array of 20 elements of type char
c) x is a function returning a pointer to a pointer to an array of 20 elements of type char
d) x is an array of 20 pointers to functions returning char

A

b) x is a pointer to a function returning a pointer to an array of 20 elements of type char

Declare x as function returning pointer to pointer to array[20] of char

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

What is paging in computer systems?

A

Paging is a memory management scheme used to allocate and manage memory in a computer system. It divides the physical memory and virtual memory used by applications into fixed-size blocks called pages.

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

How does addressing of memory work in modern computer systems?

A

Addressing of memory is the process of mapping a logical address to a physical address.

In modern computer systems, this mapping is done through hardware components such as the Memory Management Unit (MMU).

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

What is a Memory Management Unit (MMU) and what is its role in memory management?

A

A Memory Management Unit (MMU) is a hardware component that maps virtual memory to physical memory in a computer system.

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

What is the process of mapping a virtual address to a physical address?

A

Address mapping involves translating a virtual address into a corresponding physical address. This is done by hardware components such as the MMU.

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

How is a physical address calculated from a virtual address?

A

To calculate the physical address from a virtual address, the MMU splits the virtual address into a page number and an offset, looks up the corresponding physical page number in a page table, and concatenates it with the offset.

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

What is a page table and how is it used in memory management?

A

A page table is a data structure used by the MMU to map virtual pages to physical pages in memory.

18
Q

What is the purpose of dividing memory into fixed-size blocks called pages?

A

Dividing memory into fixed-size blocks called pages enables efficient memory management and reduces fragmentation.

19
Q

What is the size of a typical page in modern computer systems?

A

The size of a typical page in modern computer systems is 4KB (4096 bytes).

20
Q

What is the benefit of using paging in memory management?

A

Paging allows for efficient use of memory and simplifies memory management in computer systems.

21
Q

What are the advantages of using a Memory Management Unit in the address translation process?

A

The MMU provides faster address translation and better memory protection by mapping virtual addresses to physical addresses and enforcing memory access permissions.

22
Q

What is concurrency in computer science?

A

Concurrency in computer science is the ability of a program or operating system to handle multiple tasks or processes simultaneously, by allowing different parts of a program to run simultaneously.

23
Q

What is parallelism in computer science?

A

Parallelism in computer science is the ability to execute multiple tasks or processes simultaneously by using multiple processors or cores.

24
Q

How do concurrency and parallelism differ?

A

Concurrency deals with the simultaneous execution of multiple tasks within a single process, while parallelism deals with the simultaneous execution of multiple processes or tasks across multiple processors or cores.

25
Q

What is an example of concurrency in computer science?

A

An example of concurrency in computer science is a web browser that can render a webpage while simultaneously downloading other resources in the background.

26
Q

What is an example of parallelism in computer science?

A

An example of parallelism in computer science is a program that performs mathematical calculations by dividing them into smaller tasks and executing them in parallel across multiple processors.

27
Q

How does concurrency improve program performance and responsiveness?

A

Concurrency can improve program performance and responsiveness by allowing multiple tasks to be executed simultaneously, which reduces the need for blocking and waiting.

28
Q

How does parallelism improve program performance for compute-intensive tasks?

A

Parallelism can improve program performance for compute-intensive tasks by dividing them into smaller tasks that can be executed in parallel across multiple processors or cores, which reduces the overall execution time.

29
Q

What is multi-threading and how is it related to concurrency?

A

Multi-threading is a technique used to achieve concurrency by creating multiple threads of execution within a single process, allowing different parts of a program to run simultaneously.

30
Q

What is multi-processing and how is it related to parallelism?

A

Multi-processing is a technique used to achieve parallelism by executing multiple processes or tasks across multiple processors or cores.

31
Q

What are some benefits of using concurrency and parallelism in computer programs?

A

Some benefits of using concurrency and parallelism in computer programs include improved program performance, responsiveness, and scalability, as well as better utilization of hardware resources.

32
Q

Which of the following encompasses the other three?
(a) sequence structure
(b) iteration structure
(c) control structure
(d) selection structure

A

(c) control structure

33
Q

Which of the following is an iteration statement?
(a) if
(b) if…else
(c) do…while
(d) switch

A

(c) do…while

34
Q

How many types of control statements exist in C?
(a) 3
(b) 7
(c) 5
(d) 2

A

(a) 3

35
Q

Normally, statements in a program are executed one after the
other in the order in which they are written. This is called __________ ex-ecution.
a) inline
b) seeking
c) ordered
d) sequential

A

d) sequential

36
Q

Various C statements enable you to specify that the next statement to be executed may be other than the next one in sequence. This is called __________.
a) change of order
b) instruction skipping
c) transfer of control
d) rerouting

A

c) transfer of control

37
Q

Bohm and Jacopini’s work demonstrated that all programs could be written in terms of only three control statements, namely sequence,
__________ and iteration.
a) selection
b) serialization
c) sorting
d) searching

A

a) selection

38
Q

The __________ is called a single-selection statement.
a) if
b) when
c) if…else
d) switch

A

a) if

39
Q

The __________ is called a double selection statement.
a) if
b) when
c) if …else
d) switch

A

c) if …else

40
Q

The __________ is called a multiple selection statement.
a) if
b) when
c) if …else
d) switch

A

d) switch