C LAB QUESTIONS
C LAB QUESTIONS
The return keyword ends the execution of the function and return a value or signal to the
calling function
The base case is a fundamental part of recursive function. It dictates where the
recursion ends and begins to return values.
Recursion terminates when it reaches the base
Logic AND returns true only if all values are true for example num1, num2, and num3
are true. If one value is not true, then returns false.
Logical OR returns true if at least one value is true that is to say check one of the
values is positive.
BOOK QUESTIONS LAB PART 2
1. 1D Array
Write a C program to read n integers into a 1D array, then find and display the largest and
smallest elements. Include a function findMinMax that take the array and its size as
parameters.
2. 2D Array:
Create a C program that reads a 3×3 matrix from the user and computes the sum of each
row and each column. Display the matrix, the row sums, and the column sums.
3. 2D Array:
Write a c program to perform matrix multiplication for two matrices provided by the user.
Ensure that the matrices dimensions are compatible and display the resulting matrix.
4. 3D Array:
Write a C program to store and display sales data for 3 products across 4 regions for two
quarters. Use a 3D array, and calculate the total sales for each product across all regions
and quarters.
5. Mixed Array Operation:
Explain the advantages of using Array for storing data.
Efficient and Fast Access. Arrays allow direct and efficient access to any element in
the collection with constant access time, as the data is stored in contiguous memory
locations.
Memory Efficiency. Arrays store elements in contiguous memory, allowing efficient
allocation in a single block and reducing memory fragmentation.
Versatility: Arrays can be used to store a wide range of data types, including integers,
characters, floating-point number, and even complex data structures such as objects
and pointers.
Compatibility with hardware: The array data structure is compatible with most
hardware architectures, which make it a versatile tool for programming in a wide
range of environments.
NO.1 Union:
Write a program to define a union `Date` with fields for an integer, a float, and a
character. Demonstrate how modifying one field affects the other fields, explain the
behaviour observed.
2. Structure:
Create a structure Student with fields for name, roll number, and marks in three subjects.
Write a program to read and display the details of n students and compute their average
marks.
3. Structure with Nested Structures:
Define a structure Employee with fields for name, ID, and a nested structure Address that
includes city, state, and zip code. Write a program to input and display the details of an
employee.
4. Union vs. Structure:
Explain the differences between Unions and Structures
A structure is a custom data type that holds multiple members of different data type under
a single unit where union is a user defined data type that combine object of different data
type in the exact memory location. Differences include:
Memory Allocation. Structure allocates memory for all its members while union
allocates memory only for the largest member.
Total Size. Structure shows sum of sizes of all members whereas union shows size of
the largest member.
Data Storage. Structure can store values for all members simultaneously while union
can store value for only one member at a time.
Accessing Members. In structure, all members can be accessed at any time while in
union only the last stored member can be accessed.
Modification Impact. Modifying a member in structure doesn’t affect other members
whereas in union modifying one member may overwrite other members.