0% found this document useful (0 votes)
30 views4 pages

C Programming 3marks Answers

The document contains a model question paper with answers related to C programming, covering basic concepts such as variables, constants, loops, recursion, and file handling. It includes definitions, syntax examples, and comparisons between different programming constructs. Key features of C, as well as the use of library functions and data structures like arrays, structs, and unions, are also discussed.

Uploaded by

mohammedthahlil
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)
30 views4 pages

C Programming 3marks Answers

The document contains a model question paper with answers related to C programming, covering basic concepts such as variables, constants, loops, recursion, and file handling. It includes definitions, syntax examples, and comparisons between different programming constructs. Key features of C, as well as the use of library functions and data structures like arrays, structs, and unions, are also discussed.

Uploaded by

mohammedthahlil
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

MODEL QUESTION PAPER – ANSWERS

C PROGRAMMING (3 Marks Questions)


Q1. Define a variable and constant in C with an example.

A variable is a named memory location whose value can change during program execution.
Example: int x = 10;
A constant is a fixed value that cannot change during program execution. Example: const
float PI = 3.14;

Q2. List any three features of the C programming language.

1. Structured programming language.


2. Supports low-level (bitwise, memory) operations.
3. Portable and efficient.

Q3. Differentiate between `while` and `do…while` loops.

while do-while

Condition is checked first then Statement(s) is executed atleast once,


statement(s) is executed. thereafter condition is checked.

Variable in condition is initialized variable may be initialized before or


before the execution of loop. within the loop.

while loop is entry controlled loop. do-while loop is exit controlled loop.

while(condition) do
{ {
statement(s); statement(s);
} } while(condition);

Q4. What is recursion? Give one simple example.

Recursion is a process where a function calls itself to solve a problem.


Example: factorial(n) = n * factorial(n-1).

Q5. Write the syntax of the `switch` statement in C.

switch(expression)

{
case value1:

statements;

break;
case value2:

statements;

break;
default:

statements;
}
Q6. Explain the use of `break` and `continue` statements.

break: Terminates the loop/switch immediately.


continue: Skips the current iteration and jumps to the next loop iteration.

Break Statement Continue Statement

The Break statement is used to exit from The continue statement is not used to
the loop constructs. exit from the loop constructs.

The break statement is usually used with The continue statement is not used with
the switch statement, and it can also use it the switch statement, but it can be used
within the while loop, do-while loop, or within the while loop, do-while loop, or
the for-loop. for-loop.
Q7. What is the difference between `call by value` and `call by reference`?

Call by Value: Copy of actual parameter is passed, changes don’t affect original.
Call by Reference: Address is passed, changes reflect in the original variable.

Q8. Define an array. Write the declaration for a 2D array.

An array is a collection of elements of the same data type stored in contiguous memory
locations.
Example of 2D array:

int marks[3][3];

Q9. What are library functions? Give two examples.

Library functions are pre-defined functions available in header files.


Examples: printf() from stdio.h, sqrt() from math.h.

Q10. Write the difference between `struct` and `union`.

Parameter Structure Union

A structure is a user-defined data A union is a user-defined data type


type that groups different data that allows storing different data
Definition types into a single entity. types at the same memory location.

The size is the sum of the sizes of The size is equal to the size of the
all members, with padding if largest member, with possible
Size necessary. padding.

Each member within a structure is


Memory allocated is shared by
Memory allocated unique storage area of
individual members of union.
Allocation location.

Data No data overlap as members are Full data overlap as members shares
Overlap independent. the same memory.

Accessing Individual member can be Only one member can be accessed at


Members accessed at a time. a time.
Q11. What is the use of `typedef` in C?

Ans: typedef is used to create a new name (alias) for an existing data type.
Example: typedef unsigned int UINT;

Q12. Write the syntax of opening a file in read and write mode.

FILE *fp;
fp = fopen("filename.txt", "r"); // read mode
fp = fopen("filename.txt", "w"); // write mode

You might also like