Ch1 Systems Programming and C Basics Flashcards

1
Q

What is the difference between Applications Programming and Systems Programming?

A

Applications Programming is the programming of software to provide services directly to the user (e.g., web browsers, games, word processors). Systems Programming is the programming of software that provides services for other software or the underlying computer system (e.g., operating systems, compilers, device drivers).

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

What are some examples of Systems Programming?

A

Examples include:
1. Firmware (e.g., BIOS, UEFI)
2. Operating systems (e.g., Windows, Linux)
3. Compilers and interpreters (e.g., gcc, Python)
4. Device drivers (e.g., for Bluetooth, network cards)
5. Debuggers (e.g., gdb)

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

What is the role of an Operating System?

A

An operating system manages computer hardware and software resources and provides common services for computer programs. It acts as an intermediary between applications and the computer’s hardware.

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

What are the main functionalities provided by an operating system?

A

File I/O: Manages file system organization and access permissions.
Device I/O: Allows communication with devices (e.g., keyboard, printer).
Process Management: Manages running processes, multitasking, and memory allocation.
Virtual Memory: Provides memory to processes, appearing as contiguous memory.
Scheduling: Manages CPU time and device access sharing.

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

What is the shell in a Unix-based system, and what are the three major shells?

A

A shell is a command-line interface that allows access to an operating system’s services. The three major shells are:
1. sh (Bourne shell)
2. bash (Bourne-again shell, default for Linux)
3. csh (C shell)

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

What is the purpose of a compiler in systems programming?

A

A compiler transforms source code written in one programming language (e.g., C) into another target language (e.g., machine code). In this course, the GNU compiler (gcc) is used.

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

What is the purpose of a debugger, and what command is used to run a debugger in C?

A

A debugger is used to test and debug other programs by controlling their execution and inspecting variables and control flow. The command to run a debugger in C is gdb.

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

What are the steps to write, compile, and run a C program?

A
  1. Writing: Write the program in a .c file.
  2. Compiling: Use gcc -c to compile the .c file into an object file (.o).
  3. Linking: Use gcc -o to link the object file with libraries to create an executable.
  4. Running: Execute the program using ./executable_name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between pass-by-value and pass-by-reference in C?

A

Pass-by-value: A copy of the value is passed to the function. Changes to the parameter do not affect the original variable.
Pass-by-reference: The address of the variable is passed to the function. Changes to the parameter affect the original variable.

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

How do you prevent buffer overflow when using scanf() to read strings?

A

You can specify a width limit in the format string to prevent buffer overflow. For example:
scanf(“%19s”, name); // Reads up to 19 characters, leaving space for the null terminator.

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

What is the purpose of the #include <stdio.h> directive in a C program?</stdio.h>

A

The #include <stdio.h> directive tells the compiler to include the standard input/output header file, which contains declarations for functions like printf() and scanf().</stdio.h>

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

What is the difference between printf() and scanf() in C?

A

printf() is used to display output to the console. scanf() is used to read input from the user.

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

What is the purpose of the return 0; statement in the main() function?

A

The return 0; statement indicates that the program has executed successfully. A non-zero value typically indicates an error.

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

What is the difference between int, float, and double in C?

A

int is used for integer values. float is used for single-precision floating-point numbers. double is used for double-precision floating-point numbers.

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

How do you generate random numbers in C, and how do you ensure they are different each time the program runs?

A

Use the rand() function to generate random numbers. To ensure different numbers each time, use srand(time(NULL)); to seed the random number generator with the current time.

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

What is the purpose of the break statement in a loop?

A

The break statement is used to exit a loop immediately, skipping the remaining iterations.

17
Q

What is the purpose of the continue statement in a loop?

A

The continue statement skips the rest of the current iteration and proceeds to the next iteration of the loop.

18
Q

What is the difference between ++x and x++ in C?

A

++x increments the value of x before using it in the expression. x++ increments the value of x after using it in the expression.

19
Q

What is the purpose of the #define directive in C?

A

The #define directive is used to define constants or macros. For example:
#define PI 3.14159

20
Q

What is the difference between char, short, and long in C?

A

char is used for single characters or small integers (1 byte). short is used for short integers (typically 2 bytes). long is used for long integers (typically 4 or 8 bytes).