C Programming Exam Questions and Guidelines
C Programming Exam Questions and Guidelines
In C, operator precedence determines the order in which operators are evaluated in expressions. Operators with higher precedence are evaluated before operators with lower precedence. Associativity determines the order of evaluation for operators of the same precedence level. For example, in the expression '3 + 2 * 5', the multiplication operator (*) has higher precedence than the addition operator (+), so the expression is evaluated as '3 + (2 * 5)' resulting in 13. If operators have the same precedence, associativity rules apply. For instance, the operators '+' and '-' are left-associative, so '10 - 5 + 3' is evaluated as '(10 - 5) + 3' .
The 'break' statement in C exits the nearest enclosing loop or switch statement immediately, effectively terminating the loop/switch. The 'continue' statement skips the rest of the code inside the current loop iteration and jumps to the next iteration of the loop. Contrastingly, the 'goto' statement allows for an unconditional jump to the labeled statement specified in the program, which can lead to a less structured flow of control if not used carefully. These statements are used to alter the normal sequence of execution in a program .
C tokens are the smallest individual units in a C program used for constructing statements. The commonly used types of tokens in C include keywords (e.g., int, return), identifiers (e.g., variable names), constants (e.g., numerical literals), strings (e.g., "Hello World"), operators (e.g., +, -), and punctuation symbols (e.g., ",", ";"). These tokens serve as the building blocks for C programming and are essential for understanding and writing correct syntax .
One-dimensional arrays in C are linear lists of a specific data type, declared with a single set of square brackets indicating the number of elements. For instance, 'int arr[5];' declares a one-dimensional array of integers. Two-dimensional arrays, in contrast, are like arrays of arrays, declared with two sets of square brackets, representing rows and columns. For example, 'int matrix[3][4];' declares a two-dimensional array. While one-dimensional arrays are used for simple data lists, two-dimensional arrays are suitable for data represented in tabular form, such as matrices .
System software refers to programs designed to manage and control computer hardware, providing a platform for application software. Examples include operating systems, compilers, and device drivers. Application software, such as Microsoft Word, is designed to help users perform specific tasks like word processing. While system software serves as an interface between hardware and user applications to ensure the system functions smoothly, application software directly facilitates user-oriented tasks .
C provides several file handling modes to control how a file is accessed within a program. Common modes include 'r' (read), 'w' (write), 'a' (append), 'r+' (read and write), 'w+' (write and read), and 'a+' (append and read). Each mode determines the operations allowed on the file and, in some cases, what happens to existing data. For example, 'r' opens an existing file for reading, 'w' creates a file or truncates the existing file to zero length for writing, and 'a' opens a file for appending at the end. Syntax for opening a file: 'FILE *fp = fopen("file.txt", "r");' .
Arrays in C are collections of data items of the same type, stored in contiguous memory locations, which allows for simple iteration and indexing through subscripting. Pointers, on the other hand, are variables that store memory addresses and can be used to dynamically manipulate data and allocate memory. From an efficiency standpoint, pointers can be more flexible, allowing for dynamic programming techniques, lower memory usage through dynamic allocation, and efficient manipulation of data with direct memory access. However, improper use of pointers can lead to memory leaks and segmentation faults. Conversely, arrays offer simplicity and safety but lack flexibility compared with pointers .
To declare a structure in C, you first use the 'struct' keyword followed by the structure name and the member declarations enclosed in braces. To initialize the structure, you can either use a block of values or assign values individually after declaration. For example: ```c struct Student { char name[50]; int age; float gpa; }; struct Student student1 = {"Alice", 20, 3.5}; ``` This declares a structure named 'Student' and initializes 'student1' with specified values .
Volatile memory, like RAM, is used for fast data access and temporary storage during active processes. It loses its data when power is turned off, making it unsuitable for long-term storage but ideal for tasks that require quick access to data. Non-volatile memory, in contrast, retains stored data even without power, examples being ROM and hard disk drives. Non-volatile memory is essential for storing data and system files persistently, whereas volatile memory optimizes speed and efficiency for active data processing .
Input devices in a computer system are used to provide data and control signals to the computer. Examples include keyboards for typing, mice for navigation, and microphones for audio input. Output devices, on the other hand, are used to convey the processed data from the computer to the user or another device. Examples include monitors for display, printers for printing documents, and speakers for sound output. These devices play a fundamental role in the interaction between the user and the computer system .