CS609 – System Programming: Midterm Important Subjective (40 Solved Q&As)
Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS609 Course Page · CS609 MCQ Pack (261 MCQs)
-
Write the CreateFile() statement to create a file "vuSample.txt" for read and write access with no sharing, default security attributes, to be overwritten if it already exists, with all other parameters set to NULL.
Topic: Core Subjective Topics
HANDLE hFile = CreateFile("vuSample.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); GENERIC_READ | GENERIC_WRITE gives read/write access, the share mode 0 means the file is not shared, CREATE_ALWAYS overwrites the file if it already exists (and creates it if it does not), and the function returns a HANDLE to the opened file.
-
Write a program that gets the last error code using GetLastError() and displays the error message using FormatMessage().
Topic: Core Subjective Topics
#include <windows.h> #include <stdio.h> void main() { DWORD dwError = GetLastError(); LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0, NULL); printf("Error: %s", (char*)lpMsgBuf); } GetLastError() returns the last error code of the calling thread, and FormatMessage() converts that code into a readable message string.
-
Write the names of the functions used to change (set) the position of the file pointer in Windows file handling.
Topic: Core Subjective Topics
Two functions are used to move the file pointer: 1. SetFilePointer() — works with 32-bit file positions and also returns the new pointer position. 2. SetFilePointerEx() — works with 64-bit (LARGE_INTEGER) file positions, so it supports very large files.
-
Write the signature (prototype) of the SetFilePointer() function and name the values of its dwMoveMethod parameter.
Topic: Core Subjective Topics
DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod); The dwMoveMethod parameter can take three values: 1. FILE_BEGIN — the starting point is the beginning of the file. 2. FILE_CURRENT — the starting point is the current position of the file pointer. 3. FILE_END — the starting point is the end of the file.
-
Write the parameters of the CreateFile() function.
Topic: Core Subjective Topics
CreateFile() takes seven parameters: 1. lpFileName — name of the file to create or open. 2. dwDesiredAccess — access mode, e.g. GENERIC_READ, GENERIC_WRITE. 3. dwShareMode — sharing mode of the file. 4. lpSecurityAttributes — pointer to a SECURITY_ATTRIBUTES structure. 5. dwCreationDisposition — action to take if the file exists or does not exist. 6. dwFlagsAndAttributes — file attributes and flags. 7. hTemplateFile — handle to a template file.
-
What is the return type of the CreateFile() function? Also write the parameters of DeleteFile().
Topic: Core Subjective Topics
CreateFile() returns a HANDLE — a handle to the file or device it opens. If the function fails, it returns INVALID_HANDLE_VALUE. DeleteFile() takes a single parameter: BOOL DeleteFile(LPCTSTR lpFileName);
-
Define the purpose of the dwShareMode parameter and write its values.
Topic: Core Subjective Topics
dwShareMode decides how the file will be shared with other processes while it is open. Its values are: 1. 0 — the file cannot be shared; no other process can open it. 2. FILE_SHARE_READ — other processes can open the file for reading. 3. FILE_SHARE_WRITE — other processes can open the file for writing. 4. FILE_SHARE_DELETE — other processes can open the file for delete access.
-
How many standard input/output devices are there in an operating system? Write their names, and also write the values that can be passed to the nStdHandle parameter of GetStdHandle().
Topic: Core Subjective Topics
There are three standard I/O devices: 1. Standard Input device 2. Standard Output device 3. Standard Error device The nStdHandle parameter of GetStdHandle() can take three values: 1. STD_INPUT_HANDLE 2. STD_OUTPUT_HANDLE 3. STD_ERROR_HANDLE
-
Write the names of the five predefined root keys of the Windows Registry.
Topic: Core Subjective Topics
1. HKEY_LOCAL_MACHINE (HKLM) 2. HKEY_CURRENT_CONFIG (HKCC) 3. HKEY_CLASSES_ROOT (HKCR) 4. HKEY_CURRENT_USER (HKCU) 5. HKEY_USERS (HKU)
-
Which predefined key of the registry stores user-specific configuration settings? Also write the utility of the Windows Registry.
Topic: Core Subjective Topics
HKEY_CURRENT_USER stores the user-specific configuration settings of the currently logged-in user. The Windows Registry is a hierarchical database that stores configuration settings and options for the operating system, installed applications, hardware devices and users. Programs read and write their settings in the registry instead of keeping separate configuration files.
-
Briefly describe the RegSetValueEx() and RegDeleteValue() functions.
Topic: Core Subjective Topics
RegSetValueEx() sets the data of a named value under an open registry key. It takes the key handle, the value name, the data type (such as REG_SZ or REG_DWORD) and the actual data to store. RegDeleteValue() removes a named value from an open registry key. It takes the key handle and the name of the value to delete.
-
Write the predefined Windows data types BOOL, HANDLE, LPTSTR and DWORD with their meanings.
Topic: Core Subjective Topics
1. BOOL — an integer value used for Boolean (TRUE/FALSE) values. 2. HANDLE — a 32-bit value used as a handle to a Windows object such as a file, process or window. 3. LPTSTR — a pointer to a string that is generic for both ANSI and Unicode builds. 4. DWORD — a 32-bit unsigned integer.
-
Write the names of three flags predefined for the HeapAlloc() function.
Topic: Core Subjective Topics
1. HEAP_GENERATE_EXCEPTIONS — the function raises an exception if the allocation fails, instead of returning NULL. 2. HEAP_NO_SERIALIZE — the allocation is not serialized, so it is not thread-safe for the heap. 3. HEAP_ZERO_MEMORY — the allocated memory is initialized to zero.
-
What are the Heap APIs used in Windows programming? Which API is used to create a new heap? Write its signature.
Topic: Core Subjective Topics
The Heap API family includes HeapCreate(), HeapDestroy(), HeapAlloc(), HeapReAlloc(), HeapFree(), HeapSize(), HeapValidate() and HeapLock()/HeapUnlock(). A new heap is created with HeapCreate(): HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
-
Which API is used to get the size of a block allocated in a heap? Write its signature.
Topic: Core Subjective Topics
The HeapSize() function returns the size of a memory block allocated from a heap: SIZE_T HeapSize(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem);
-
Differentiate between errors and exceptions in Windows programming.
Topic: Core Subjective Topics
Errors are mistakes at the system or application level; they are reported through error codes (retrieved with GetLastError()) and the program decides how to react. Exceptions are abnormal events that interrupt the normal flow of the program, such as access violations or divide-by-zero; they are handled through Structured Exception Handling (SEH). In short, errors are handled by checking return values and error codes, while exceptions are handled by the exception-handling mechanism of the system.
-
In Structured Exception Handling, what code is placed in the __try block, the __except block and the __finally block?
Topic: Core Subjective Topics
The __try block contains the guarded code — the code that may raise an exception. The __except block contains the handler code that executes when an exception occurs in the __try block; its filter expression decides whether the handler runs. The __finally block contains cleanup code (such as releasing memory or closing handles) that always executes, whether the __try block finishes normally or because of an exception.
-
Write the types of floating-point exceptions that can occur in a program.
Topic: Core Subjective Topics
1. Invalid operation 2. Divide by zero 3. Overflow 4. Underflow 5. Inexact result (precision loss)
-
What is the purpose of the dwCtrlType parameter passed to a console control handler? Write its values.
Topic: Core Subjective Topics
dwCtrlType identifies the console control event for which the handler function is called. Its values are: 1. CTRL_C_EVENT — Ctrl+C pressed. 2. CTRL_BREAK_EVENT — Ctrl+Break pressed. 3. CTRL_CLOSE_EVENT — the console window is closed. 4. CTRL_LOGOFF_EVENT — a user logs off. 5. CTRL_SHUTDOWN_EVENT — the system is shutting down.
-
How many characters can be encoded in ASCII and in Unicode?
Topic: Core Subjective Topics
ASCII uses 7 bits per character and can encode 128 characters (extended ASCII uses 8 bits and encodes 256 characters). Unicode in its standard form uses 16 bits per character and can encode 65,536 characters, so it can represent the characters of almost all languages of the world.
-
Which Windows API is used to change the file access time, and in which header file is it declared? Also write the purpose of GetFileSizeEx().
Topic: Core Subjective Topics
The SetFileTime() API is used to set the creation, last access and last write times of a file, and it is declared in the Windows.h header file. GetFileSizeEx() retrieves the size of a file in bytes into a LARGE_INTEGER; it returns a BOOL value — nonzero on success and zero on failure.
-
Write the parameters of the GetTempFileName() function.
Topic: Core Subjective Topics
UINT GetTempFileName(LPCTSTR lpPathName, LPCTSTR lpPrefixString, UINT uUnique, LPTSTR lpTempFileName); 1. lpPathName — the directory path for the temporary file. 2. lpPrefixString — up to three characters used as the file-name prefix. 3. uUnique — an integer used in the file name (if zero, the system generates a unique value). 4. lpTempFileName — buffer that receives the temporary file name.
-
Write any four characters that cannot be used in Windows file names.
Topic: Core Subjective Topics
The characters / \ : | and ? cannot be used in Windows file names. (The complete reserved set is \ / : * ? " < > |.)
-
What are the features of C library file processing compared with Windows API file processing?
Topic: Core Subjective Topics
The C library functions (fopen, fread, fwrite, etc.) are portable — the same code runs on different operating systems — and they provide a higher-level, stream-based interface that is easier to use. Some character functions are generic and can migrate to the Windows API style. The Windows API functions (CreateFile, ReadFile, WriteFile, etc.) are Windows-specific but give more control over sharing, security, overlapped I/O and large files.
-
Two processes have already acquired a shared lock on a file. Can a third process acquire an exclusive lock on the same file? Why?
Topic: Core Subjective Topics
No. An exclusive lock can only be granted when no other process holds any lock (shared or exclusive) on the locked region. Because the two processes already hold shared locks, the request for an exclusive lock will fail (or wait) until all shared locks are released.
-
Write a function that sends a character to a COM port whose number is passed as a parameter, and explain how the port status is checked.
Topic: Core Subjective Topics
void sendchar(int port, char ch) { while (getcomstatus(port) == 0); /* wait until port is ready */ bioscom(_COM_SEND, ch, port); } The getcomstatus() function checks the status of the COM port using BIOS service INT 14H service #3, which returns the line status and modem status. The character is sent only when the transmitter holding register is empty, i.e. the port is ready to accept a new byte.
-
Write the steps to access the battery-powered RAM (CMOS RAM).
Topic: Core Subjective Topics
Battery-powered (CMOS) RAM is accessed through two I/O ports: 1. Write the address (number) of the desired byte to port 70H. 2. Read the value of that byte from, or write the value to, port 71H. Only ports 70H and 71H are important from the programming point of view for accessing this RAM.
-
What do XON and XOFF mean in software flow control?
Topic: Core Subjective Topics
XON and XOFF are control characters used in software flow control of serial communication. XOFF is sent by the receiver to tell the sender to stop sending data (for example when its buffer is full), and XON is sent to tell the sender to resume sending data.
-
Write a program that converts the packed BCD time values returned by INT 1AH service 02H into ASCII and displays them.
Topic: Core Subjective Topics
#include <dos.h> #include <stdio.h> void main() { union REGS in, out; char ch; in.h.ah = 0x02; /* get RTC time */ int86(0x1A, &in, &out); /* CH=hours, CL=minutes, DH=seconds (BCD) */ ch = ((out.h.ch >> 4) & 0x0F) + '0'; printf("%c", ch); ch = (out.h.ch & 0x0F) + '0'; printf("%c:", ch); ch = ((out.h.cl >> 4) & 0x0F) + '0'; printf("%c", ch); ch = (out.h.cl & 0x0F) + '0'; printf("%c:", ch); ch = ((out.h.dh >> 4) & 0x0F) + '0'; printf("%c", ch); ch = (out.h.dh & 0x0F) + '0'; printf("%c", ch); } Each BCD byte contains two decimal digits; shifting the high nibble and masking the low nibble, then adding '0' (30H), converts each digit to its ASCII code.
-
Explain INT 14H service #2 and service #3.
Topic: Core Subjective Topics
Service #2 (AH = 02H) receives a byte from the COM port: the port number is passed in DX and the received byte is returned in AL. Service #3 (AH = 03H) returns the status of the COM port: the line status is returned in AH and the modem status in AL.
-
What do THR, RBR, DLL and DLM stand for in a UART?
Topic: Core Subjective Topics
THR — Transmitter Holding Register: holds the byte to be transmitted. RBR — Receiver Buffer Register: holds the received byte. DLL — Divisor Latch Low: the low byte of the baud-rate divisor. DLM — Divisor Latch High: the high byte of the baud-rate divisor.
-
What type of information can be sent to the keyboard, and how is it sent?
Topic: Core Subjective Topics
Commands and data (such as LED settings and the typematic rate) can be sent to the keyboard. The byte is written to the data port 60H; before writing, the input buffer status is checked through the status port 64H — the byte is sent only when the input buffer is empty, so the previous byte has been accepted.
-
In parallel (PPI) interconnection, what is the working of bit D4?
Topic: Core Subjective Topics
In nibble mode, data is transferred one nibble (4 bits) at a time. Bit D4 of the control register is cleared to indicate that the low nibble is being sent, and it is set to indicate that the high nibble is being sent, so that the receiver can assemble the complete byte correctly.
-
Which condition is checked by the statement: if (((inport(lpt+1)) & 0x80) == 0x80)?
Topic: Core Subjective Topics
This condition checks the status of the printer connected to the parallel port whose base address is in lpt. It masks the status port (base+1) with 0x80, i.e. it tests bit 7 (the BUSY line, which is inverted in the status register). When the result is 0x80, the printer is not busy and is idle/ready to receive data.
-
Which bytes are used before changing the typematic rate and the LED state of the keyboard?
Topic: Core Subjective Topics
The command byte 0xF3 is sent before the typematic rate/delay byte, to tell the keyboard that the next byte contains the typematic settings. The command byte 0xED is sent before the LED byte, to tell the keyboard that the next byte contains the on/off state of the Num Lock, Caps Lock and Scroll Lock LEDs.
-
Explain the null modem connection in serial communication.
Topic: Core Subjective Topics
A null modem is used to connect two DTE devices (such as two computers) directly without modems. In the cable, the transmit line (TxD) of one side is connected to the receive line (RxD) of the other side and vice versa, and the handshaking lines are cross-connected in the same way, so each computer behaves as if it were talking to a modem.
-
Write the keyboard writing protocol (steps for writing a byte to the keyboard).
Topic: Core Subjective Topics
1. Read the status port 64H and check the Input Buffer Full (IBF) bit. 2. Wait until IBF is 0, meaning the keyboard controller is ready to accept a byte. 3. Write the command or data byte to the data port 60H. 4. The keyboard acknowledges the byte by sending the acknowledgement code 0xFA.
-
Write the purpose of interrupt 11H.
Topic: Core Subjective Topics
Interrupt 11H is the BIOS equipment-determination interrupt. It returns the equipment list of the system in the AX register, which describes the installed hardware — for example the number of parallel and serial ports, floppy drives, video mode and other devices attached to the computer.
-
In RS-232C flow control, which lines are used for data transmission and data reception? Also explain the purpose of the UART.
Topic: Core Subjective Topics
Data is transmitted on the TxD line and received on the RxD line; handshaking lines such as RTS, CTS, DSR and DTR control the flow. The UART (Universal Asynchronous Receiver Transmitter) is the serial communication chip: it converts parallel data from the computer into a serial bit stream for transmission (adding start, parity and stop bits) and converts the received serial stream back into parallel data, while also detecting errors such as parity errors.
-
How can LPT1 and LPT2 be swapped?
Topic: Core Subjective Topics
The base addresses of the parallel ports are stored in the BIOS Data Area: the word at 0040:0008 holds the base address of LPT1 and the word at 0040:000A holds the base address of LPT2. Exchanging these two words swaps LPT1 and LPT2, so programs using LPT1 actually print through the second port and vice versa.