0% found this document useful (0 votes)
7 views2 pages

C Programming Exam Questions & Answers

The document contains a C programming question paper with answers covering various topics such as computer architecture, algorithms, control structures, recursion, pointers, file management, and debugging techniques. It includes diagrams, code examples, and explanations for concepts like hardware vs software, loops, and memory functions. Additionally, it summarizes key functions and techniques relevant to C programming.

Uploaded by

patelvaidehi823
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

C Programming Exam Questions & Answers

The document contains a C programming question paper with answers covering various topics such as computer architecture, algorithms, control structures, recursion, pointers, file management, and debugging techniques. It includes diagrams, code examples, and explanations for concepts like hardware vs software, loops, and memory functions. Additionally, it summarizes key functions and techniques relevant to C programming.

Uploaded by

patelvaidehi823
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Programming Question Paper – Answers

--------------------------------------

Q.1 (a) Block Diagram of Computer


[Diagram + Explanation of Input Unit, Memory Unit, ALU, CU, Output Unit]

Q.1 (b) Computer Hardware and Software


- Hardware: Physical parts like CPU, Monitor, Keyboard
- Software: System, Application, Utility

Q.1 (c) Algorithm for finding maximum of three numbers


1. Start
2. Input a, b, c
3. If a>b & a>c -> max=a
4. Else if b>c -> max=b
5. Else max=c
6. Print max
7. Stop

--------------------------------------
Q.2 (a) Structure of for loop with example

for(initialization; condition; increment/decrement){


statements;
}

Example: for(int i=1;i<=5;i++) printf("%d ",i);

Q.2 (b) Nested if-else Example


[Code for finding largest number among 3]

Q.2 (c) Bitwise Operators Table


& | ^ ~ << >>

--------------------------------------
Q.3 (a) Need of break and continue statements
break -> Exit loop
continue -> Skip iteration

Q.3 (b) Recursion Example


factorial(n){ return n*factorial(n-1); }

Q.3 (c) String declaration and printing example

--------------------------------------
Q.4 (a) Pointer explanation and operations

Q.4 (b) Structure vs Union with examples

Q.4 (c) Program to find largest number

--------------------------------------
Q.5 (a) File management functions (fopen, fclose, fread, fwrite, etc.)

Q.5 (b) Dynamic Memory functions (malloc, calloc, realloc, free)


Q.5 (c) Error Handling in File

--------------------------------------
Debugging Techniques
- Print statements
- Breakpoints
- Step execution
- GDB tools

Call by Value vs Call by Reference Table

File handling functions summary (fseek, ftell, fread, fwrite, fprintf, fscanf, rewind)

--------------------------------------
END OF ANSWERS

Common questions

Powered by AI

The structure of a 'for' loop is defined by three main components: initialization, condition, and increment/decrement. The loop iterates as long as the condition is true. For example, the loop 'for(int i=1;i<=5;i++) printf("%d ",i);' initializes i to 1 and prints the value of i, incrementing i until it reaches 5. This is useful for repeating a set of statements a specific number of times, making it effective for tasks that require iteration over a range or collection .

Error handling in file operations is defined as methods to detect and respond to errors during file processing, such as failing to open a file. The document emphasizes its importance to prevent program crashes and ensure robustness by implementing checks and alerts for handling exceptions effectively. This ensures data integrity and user notification when issues occur .

The main components of a computer as explained in the block diagram include the Input Unit, Memory Unit, Arithmetic Logic Unit (ALU), Control Unit (CU), and Output Unit. The Input Unit receives data from external sources. The Memory Unit stores data and instructions. The ALU performs arithmetic and logical operations. The CU directs the operation of the processor. The Output Unit delivers processed data to external devices .

Structures and unions in C programming both allow for grouping variables of different types. However, they differ in memory allocation. Structures allocate memory for all members, allowing simultaneous access, while unions share the same memory space for all members, meaning only one member can hold a value at any time. The document provides examples illustrating these concepts, underscoring the trade-off between memory usage and data accessibility .

Key file management functions include fopen, fclose, fread, fwrite, among others. fopen is used to open files, fclose closes them, fread reads data from files, and fwrite writes data to files. These functions play fundamental roles in managing file input and output operations, essential for data storage and retrieval in software applications .

The algorithm for finding the maximum of three numbers involves the following steps: Start by inputting three numbers, a, b, and c. Check if a is greater than both b and c; if true, set max to a. If not, check if b is greater than c; if true, set max to b. If neither condition is true, set max to c. Finally, print the maximum value and stop. This logic ensures that the largest of the three numbers is correctly identified .

The document provides examples of using nested if-else statements for complex decision-making, such as finding the largest number among three. Nested if-else statements allow for multi-level decision processes where an initial condition is evaluated, and if true, another condition is checked within the first. This structure is vital for scenarios requiring multiple checks and decisions, enabling programmers to handle complex logical conditions effectively .

Bitwise operators are used to perform operations on binary representations of numbers. The document outlines operators such as & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), and >> (right shift). These operators are crucial for low-level programming tasks, where manipulating individual bits is required, such as in cryptography, graphics, and hardware interfaces .

Recursion is a programming concept where a function calls itself to solve a smaller instance of the same problem. The document illustrates this with the calculation of factorial(n), where the function returns n*factorial(n-1) until a base case is reached. Recursion simplifies complex problems by breaking them down into simpler sub-problems, often leading to more elegant and concise solutions .

Hardware is defined as the physical parts of a computer system, such as the CPU, monitor, and keyboard. Software refers to programs and applications, including system, application, and utility software, that run on computer hardware to perform tasks .

You might also like