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

Que & Ans CS First Year

The document discusses computer hardware and software components and their functions. It provides detailed explanations of CPU, RAM, hard drives, motherboard, GPU, power supply, input/output devices, operating systems, application software, device drivers, utilities, programming languages, compilers, interpreters, and libraries. It also includes sample questions on algorithms, program development cycles, and flowcharts with answers explaining the concepts.

Uploaded by

Atharv Mandawkar
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 views30 pages

Que & Ans CS First Year

The document discusses computer hardware and software components and their functions. It provides detailed explanations of CPU, RAM, hard drives, motherboard, GPU, power supply, input/output devices, operating systems, application software, device drivers, utilities, programming languages, compilers, interpreters, and libraries. It also includes sample questions on algorithms, program development cycles, and flowcharts with answers explaining the concepts.

Uploaded by

Atharv Mandawkar
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
You are on page 1/ 30

Important Que & Ans

Q. 1. List and explain the functions of various parts of computer hardware and
software.
Ans: Computer Hardware:
1. Central Processing Unit (CPU): The CPU is often referred to as the brain of the computer. It
performs most of the calculations and executes instructions of a computer program.
2. Random Access Memory (RAM): RAM is a type of volatile memory that provides temporary
storage for data and instructions that are currently being used by the CPU. It allows for quick access
to data, which improves overall system performance.
3. Hard Disk Drive (HDD) or Solid State Drive (SSD): HDDs and SSDs are storage devices used to
store data and software permanently. HDDs use spinning disks and magnetic heads to read and write
data, while SSDs use flash memory. They provide long-term storage for files and programs.
4. Motherboard: The motherboard is a circuit board that connects all the components of a computer
together. It provides communication between various hardware components, such as the CPU, RAM,
storage devices, and peripherals.
5. Graphics Processing Unit (GPU): The GPU is responsible for rendering images, videos, and
animations. It specializes in performing complex mathematical calculations required for graphics
processing and accelerates tasks related to visual content.
6. Power Supply Unit (PSU): The PSU converts AC power from an electrical outlet into DC power
that is required by the computer components. It supplies power to all the hardware components of the
computer.
7. Input and Output Devices: Input devices, such as keyboards and mice, allow users to provide
commands and data to the computer. Output devices, such as monitors and printers, display or
produce the results of computer processing.

Computer Software:
1. Operating System (OS): The OS is the fundamental software that manages computer hardware and
provides a user interface for interacting with the system. It handles tasks like memory management,
file management, and hardware device control.
2. Application Software: Application software refers to programs that perform specific tasks for users.
Examples include word processors, web browsers, photo editors, and video players. They are
designed to fulfill specific needs and enhance productivity or entertainment.
3. Device Drivers: Device drivers are software components that allow the operating system to
communicate and interact with hardware devices. They provide an interface for the OS to control and
utilize the features of devices like printers, scanners, and network adapters.
4. Utilities: Utility software includes programs that perform various maintenance and optimization
tasks on a computer. Examples include antivirus software, disk cleanup tools, backup utilities, and
system diagnostic tools.
5. Programming Languages: Programming languages are used to write software applications and
computer programs. They provide a way for developers to write instructions and algorithms that the
computer can understand and execute.
6. Compiler and Interpreter: Compilers and interpreters are software tools that convert high-level
programming languages into machine code or execute code directly. Compilers translate the entire
program in advance, while interpreters execute the program line by line.
7. Libraries and Frameworks: Libraries and frameworks are collections of pre-written code that
provide reusable functions and features for software development. They help programmers save time
by providing ready-made solutions for common tasks and functionalities.
These are just some of the key components and functions of computer hardware and software. The
field of computer science and technology is vast, and there are many more specific components and
software tools with specialized functions.

Q. 2. Define algorithm and state properties of it? Write an algorithm and flowchart for
swapping two numbers.
Ans: Algorithm:-An algorithm is a step-by-step procedure or set of rules designed to solve a
specific problem or accomplish a particular task. It provides a clear and unambiguous sequence of
instructions that can be followed to solve a problem, often with the goal of achieving the desired
outcome efficiently and accurately.
Properties of an algorithm:
1. Clear and Unambiguous: Each step of the algorithm should be well-defined and easily understood
without any ambiguity.
2. Input and Output: An algorithm takes one or more inputs and produces an output that is related to
the problem it is solving.
3. Finiteness: An algorithm must terminate after a finite number of steps, meaning it should not run
indefinitely.
4. Well-Defined Steps: Each step of the algorithm must be precisely defined and executable.
5. Deterministic: An algorithm should produce the same result for the same input every time it is
executed.
6. Efficiency: An algorithm should be designed to solve the problem efficiently, using the least
amount of resources and time possible.
7. Correctness: An algorithm should produce the correct output for all valid inputs and handle all
possible scenarios.
Algorithm and Flowchart for swapping two numbers:
Algorithm:
1. Start
2. Read the values of variable A and B.
3. Set temporary variable TEMP to 0.
4. Assign the value of A to TEMP.
5. Assign the value of B to A.
6. Assign the value of TEMP to B.
7. Print the values of A and B, which are now swapped.
8. Stop
Flowchart:

Note: In the flowchart, the arrows represent the flow of control, and the rectangles represent processes
or assignments. The values of variables A and B are swapped by assigning them to temporary variable
TEMP.

Q3. What do you mean by ‘Program Development Cycle’? Explain the steps involved in
that.
Ans:
The Program Development Cycle, also known as the Software Development Life Cycle
(SDLC), is a process followed by software developers to design, develop, test, and maintain
software applications. It encompasses a set of steps that guide the development process from
conception to deployment and maintenance. The program development cycle typically
consists of the following steps:
1. Requirement Gathering: In this initial phase, the software requirements are collected from
stakeholders, clients, or end-users. The goal is to understand the problem or need that the
software application should address.
2. Analysis and Planning: In this phase, the gathered requirements are analyzed, and a
detailed plan is created. This includes defining the scope, objectives, constraints, and
functionality of the software. The team also determines the feasibility of the project in terms
of resources, time, and budget.
3. Design: In this phase, the software architecture and system design are created based on the
requirements. The design includes both the high-level structure (e.g., modules, components)
and the low-level details (e.g., algorithms, data structures) of the software application.
4. Implementation: In this phase, the actual coding or programming of the software is
performed. The developers write the code according to the design specifications using
programming languages, frameworks, and tools. The implementation phase involves creating
and integrating different modules and components.
5. Testing: Once the code is implemented, thorough testing is conducted to identify and fix
any defects, bugs, or errors. Various testing techniques such as unit testing, integration
testing, system testing, and acceptance testing are employed to ensure the software meets the
requirements and functions as intended.
6. Deployment: After successful testing, the software is deployed or released to the end-users
or clients. It involves installing the software on the target environment and making it
available for use. Deployment may also include user training, data migration, and system
configuration.
7. Maintenance: Once the software is deployed, it enters the maintenance phase. During this
phase, any issues, bugs, or enhancements reported by users are addressed. Regular updates,
bug fixes, and performance improvements may be carried out to ensure the software remains
functional and up-to-date.
It's important to note that the program development cycle is not a linear process, but rather an
iterative one. Feedback from each phase can lead to revisions in earlier steps, ensuring that
the software meets the desired requirements and quality standards. The cycle may repeat for
new features or versions of the software, and the maintenance phase can continue for the
entire lifecycle of the software application.
Q4. Explain the symbols in a flowchart. Draw a flowchart to find the largest among two
numbers.
Ans: Symbols in a flowchart:
1. Start/End: Represents the beginning and end points of a flowchart. It is usually depicted as a
rounded rectangle with the word "Start" or "End" inside.

2. Process: Represents a specific action or process performed in the flowchart. It can be any
operation, calculation, or task that needs to be executed. It is usually depicted as a rectangle
with rounded corners.

3. Input/Output: Represents the input or output of data in the flowchart. It is used to indicate
the exchange of information between the user and the program. Input is typically represented
as a parallelogram, and output is represented as a rectangle with rounded corners.
4. Decision: Represents a conditional or branching point in the flowchart. It is used to make
decisions based on specific conditions or criteria. It is usually depicted as a diamond shape,
with arrows flowing in different directions based on the decision outcomes.

5. Connector: Represents a connection between different parts of the flowchart. It is used to


show the flow of control or the continuation of a process from one point to another. It is
usually depicted as a small circle or dot.

6. Flow lines: It represents the exact sequence in which instructions are executed. Arrows are
used to represent the flow lines in a flowchart. The symbol given below is used for
representing the flow lines.

Flowchart to find the largest among two numbers:

Explanation:
1. The flowchart begins with the "Start" symbol.
2. The values of two numbers, A and B, are inputted.
3. The "Largest" variable is initially set to A.
4. A decision is made to check if B is greater than A. If it is, the value of "Largest" is updated to B.
5. The flow continues to the "Print Largest" symbol, where the largest number is outputted.
6. Finally, the flowchart ends with the "End" symbol.
This flowchart determines the largest among two numbers and demonstrates the use of input, process,
decision, and output symbols commonly used in flowcharts.
Q5. What are the different data types in C.
Ans:- In the C programming language, there are several built-in data types that allow you to store
different kinds of values. The common data types in C are as follows:

The following are some main primitive data types in C:


Integer Data Type:
The integer datatype in C is used to store the whole numbers without decimal values. Octal
values, hexadecimal values, and decimal values can be stored in int data type in C.
Range: -2,147,483,648 to 2,147,483,647
Size: 4 bytes
Format Specifier: %d
Syntax of Integer
We use int keyword to declare the integer variable:
int var_name;
The integer data type can also be used as
unsigned int: Unsigned int data type in C is used to store the data values from zero to
positive numbers but it can’t store negative values like signed int.
short int: It is lesser in size than the int by 2 bytes so can only store values from –32,768 to
32,767.
long int: Larger version of the int datatype so can store values greater than int.
unsigned short int: Similar in relationship with short int as unsigned int with int.
Character Data Type:-
Character data type allows its variable to store only a single character. The size of the
character is 1 byte. It is the most basic data type in C. It stores a single character and requires
a single byte of memory in almost all compilers.
Range: (-128 to 127) or (0 to 255)
Size: 1 byte
Format Specifier: %c
Syntax of char
The char keyword is used to declare the variable of character type:
char var_name;
Float Data Type
In C programming float data type is used to store floating-point values. Float in C is used to
store decimal and exponential values. It is used to store decimal numbers (numbers with
floating point values) with single precision.
Range: 1.2E-38 to 3.4E+38
Size: 4 bytes
Format Specifier: %f
Syntax of float
The float keyword is used to declare the variable as a floating point:
float var_name;
Double Data Type:-
A Double data type in C is used to store decimal numbers (numbers with floating point
values) with double precision. It is used to define numeric values which hold numbers with
decimal values in C.
The double data type is basically a precision sort of data type that is capable of holding 64
bits of decimal numbers or floating points. Since double has more precision as compared to
that float then it is much more obvious that it occupies twice the memory occupied by the
floating-point type. It can easily accommodate about 16 to 17 digits after or before a decimal
point.
Range: 1.7E-308 to 1.7E+308
Size: 8 bytes
Format Specifier: %lf
Syntax of Double
The variable can be declared as double precision floating point using the double keyword:
double var_name;
Void Data Type:-
The void data type in C is used to specify that no value is present. It does not provide a result
value to its caller. It has no values and no operations. It is used to represent nothing. Void is
used in multiple ways as function return type, function arguments as void, and pointers to
void.
Syntax:
// function return type void
void exit(int check);
// Function without any parameter can accept void.
int print(void);
// memory allocation function which
// returns a pointer to void.
void *malloc (size_t size);

6. Write a program using conditional operators to determine whether a year entered


through the keyboard is a leap year or not.
Ans:- A program written in C that uses conditional operators to determine whether a year is a
leap year or not:
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
// Using conditional operators to check leap year condition
// Leap year is divisible by 4 but not divisible by 100, except if it is divisible by 400
int isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
if (isLeapYear) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}
return 0;
}
Explanation:
1. The program starts by declaring a variable `year` to store the input year.
2. The user is prompted to enter a year using `printf` and `scanf`.
3. The conditional expression `(year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)` is
used to determine whether the year is a leap year or not.
- If the year is divisible by 4 but not divisible by 100 (except if it is divisible by 400), the
expression evaluates to `true`, indicating a leap year.
- If the condition is not met, the expression evaluates to `false`, indicating a non-leap year.
4. The program uses `if` statement to check the value of `isLeapYear` and prints the
appropriate message accordingly.
Please note that this program assumes the input year is a positive integer. Additionally, it does
not perform input validation, so providing invalid input (e.g., non-numeric values) may lead
to unexpected behavior.
7. What are the different searching and sorting algorithms in detail.
Ans:- These are some commonly used searching and sorting algorithms in C.
Searching Algorithms:
1. Linear Search:
- Linear search is a simple searching algorithm that sequentially checks each element in a
list until a match is found or the entire list has been traversed.
- It is suitable for both sorted and unsorted arrays.
- Time Complexity: O(n) - Linear time complexity.
2. Binary Search:
- Binary search is an efficient searching algorithm that can only be applied to sorted arrays.
- It repeatedly divides the search interval in half by comparing the target element with the
middle element of the array and eliminates the half in which the target cannot reside.
- Time Complexity: O(log n) - Logarithmic time complexity.
Sorting Algorithms:
1. Bubble Sort:
- Bubble sort compares adjacent elements and swaps them if they are in the wrong order.
This process is repeated until the entire list is sorted.
- It is a simple and easy-to-understand sorting algorithm.
- Time Complexity: O(n^2) - Quadratic time complexity.
2. Insertion Sort:
- Insertion sort builds the final sorted array one item at a time. It iterates over the array,
comparing each element with the sorted portion and inserting it in the correct position.
- It is efficient for small data sets or partially sorted arrays.
- Time Complexity: O(n^2) - Quadratic time complexity.
3. Selection Sort:
- Selection sort divides the array into a sorted and an unsorted region. It repeatedly selects
the minimum element from the unsorted region and swaps it with the first unsorted element.
- It is an in-place sorting algorithm but not suitable for large data sets.
- Time Complexity: O(n^2) - Quadratic time complexity.
4. Merge Sort:
- Merge sort is a divide-and-conquer algorithm. It recursively divides the array into two
halves, sorts them separately, and then merges the two sorted halves into a single sorted array.
- It has a stable sort property and guarantees a worst-case time complexity of O(n log n).
- Time Complexity: O(n log n) - Log-linear time complexity.
5. Quick Sort:
- Quick sort is another divide-and-conquer algorithm. It selects a pivot element, partitions
the array around the pivot, and recursively applies the same process to the sub-arrays.
- It has good average-case performance and is widely used due to its efficiency.
- Time Complexity: O(n log n) - Log-linear time complexity on average.
6. Heap Sort:
- Heap sort builds a binary heap from the array and repeatedly extracts the maximum
element (in a max-heap) and places it at the end of the sorted array.
- It has a worst-case time complexity of O(n log n) and is an in-place sorting algorithm.
- Time Complexity: O(n log n) - Log-linear time complexity.
7. Radix Sort:
- Radix sort is a non-comparative sorting algorithm that sorts integers by grouping digits. It
sorts the numbers digit by digit, from the least significant digit to the most significant digit.
- It is efficient for sorting numbers with a fixed number of digits.
- Time Complexity: O(d * (n + b)) - Linear time complexity, where d is the number of
digits, n is the number of elements, and b is the base (usually 10 for decimal numbers).
8. Write a program to copy the contents of one array into another in the reverse order.
Ans:- C program that copies the contents of one array into another array in reverse order:
Program:-
#include <stdio.h>
#define MAX_SIZE 100
void reverseCopyArray(int source[], int destination[], int size)
{
int i, j;
// Copy elements in reverse order
for (i = size - 1, j = 0; i >= 0; i--, j++)
{
destination[j] = source[i];
}
}
int main()
{
int source[MAX_SIZE];
int destination[MAX_SIZE];
int size, i;
printf("Enter the size of the array: ");
scanf("%d", &size);
printf("Enter elements of the array:\n");
for (i = 0; i < size; i++)
{
scanf("%d", &source[i]);
}
// Call the function to copy in reverse order
reverseCopyArray(source, destination, size);
printf("Contents of the original array: ");
for (i = 0; i < size; i++)
{
printf("%d ", source[i]);
}
printf("\nContents of the reversed array: ");
for (i = 0; i < size; i++)
{
printf("%d ", destination[i]);
}
return 0;
}
Explanation:
1. The program defines a maximum size for the arrays using a macro `MAX_SIZE`.
2. The function `reverseCopyArray` takes three arguments: the source array, the destination
array, and the size of the arrays.
3. Inside the function, a loop iterates through the source array in reverse order and copies the
elements into the destination array.
4. The `main` function prompts the user to enter the size of the array and the elements of the
array.
5. After that, it calls the `reverseCopyArray` function, passing the source array, destination
array, and size as arguments.
6. Finally, it displays the contents of both the original array and the reversed array using
separate loops.
Note: Make sure the size of the arrays does not exceed the `MAX_SIZE` limit defined in the
program. Also, the program assumes that the input elements are integers.
9. Explain call by value and call by reference in detail with example.
Ans:-
Functions can be invoked in two ways: Call by Value or Call by Reference. These two ways
are generally differentiated by the type of values passed to them as parameters.
The parameters passed to the function are called actual parameters whereas the parameters
received by the function are called formal parameters.
1. Call By Value
In call by value method of parameter passing, the values of actual parameters are copied to
the function’s formal parameters.
There are two copies of parameters stored in different memory locations.
 One is the original copy and the other is the function copy.
 Any changes made inside functions are not reflected in the actual parameters of the
caller.
Example of Call by Value
The following example demonstrates the call-by-value method of parameter passing
// C program to illustrate call by value
#include <stdio.h>
// Function Prototype
void swapx(int x, int y);
// Main function
int main()
{
int a = 10, b = 20;
// Pass by Values
swapx(a, b);
printf("In the Caller:\na = %d b = %d\n", a, b);
return 0;
}
// Swap functions that swaps
// two values
void swapx(int x, int y)
{
int t;
t = x;
x = y;
y = t;
printf("Inside Function:\nx = %d y = %d\n", x, y);
}
Output
Inside Function:
x = 20 y = 10
In the Caller:
a = 10 b = 20
Thus actual values of a and b remain unchanged even after exchanging the values of x and y
in the function.

2. Call by Reference
In call by reference method of parameter passing, the address of the actual parameters is
passed to the function as the formal parameters.
 Both the actual and formal parameters refer to the same locations.
 Any changes made inside the function are actually reflected in the actual parameters
of the caller.
Example of Call by Reference
The following C program is an example of call by reference method.
// C program to illustrate Call by Reference
#include <stdio.h>
// Function Prototype
void swapx(int*, int*);
// Main function
int main()
{
int a = 10, b = 20;
// Pass reference
swapx(&a, &b);
printf("Inside the Caller:\na = %d b = %d\n", a, b);
return 0;
}
// Function to swap two variables
// by references
void swapx(int* x, int* y)
{
int t;
t = *x;
*x = *y;
*y = t;
printf("Inside the Function:\nx = %d y = %d\n", *x, *y);
}
Output
Inside the Function:
x = 20 y = 10
Inside the Caller:
a = 20 b = 10
Thus actual values of a and b get changed after exchanging values of x and y.
10. Write a function power (a, b) to calculate the value of a raised to b.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
int power(int a, int b);
int main()
{
int a, b, res;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
res = power(a, b);
printf("Result: %d", res);
}
int power(int a, int b)
{
int x;
x = pow(a, b);
return x;
}
Output:
Enter a: 2
Enter b: 3
Result: 8

11. A 5-digit positive integer is entered through the keyboard, write a recursive and a
non-recursive function to calculate sum of digits of the 5-digit number.
Ans:-
#include<stdio.h>
int rec_func(int num);
int non_rec_func(int num);
void main( )
{
int num, rec, non_rec;
printf("Enter an integer: ");
scanf("%d", &num);
rec = rec_func(num);
non_rec = non_rec_func(num);
printf("\n Calculate sum using recursion: %d",rec);
printf("\n Calculate sum without recursion: %d",non_rec);
}
int rec_func(int num)
{
if (num==0)
{
return 0;
}
return (num%10+rec_func(num/10));
}
int non_rec_func(int num)
{
int res, count=0;
while(num!=0)
{
res=num%10;
count += res; //count=count+res;
num = num/10;
}
return count;
}
Output:
Enter an integer: 12345
Calculate sum using recursion: 15
Calculate sum without recursion: 15

12. Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In
a Fibonacci sequence the sum of two successive terms gives the third term. Following
are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89 ……
Ans:-
#include<stdio.h>
int fibo(int num);
void main()
{
int num,c=0,i;
printf("Enter number: ");
scanf("%d", &num);
printf("Fibonacci Series:\n");
for(i=1;i<=num;i++)
{
printf("%d\n", fibo(c));
c++;
}
}
int fibo(int num)
{
if(num==0)
{
return 0;
}
else if(num==1)
{
return 1;
}
//fibonacci = 1 1 2 3 5 8
// where n = (n-1) + (n-2)
else
{
return (fibo(num-1)+fibo(num-2));
}
}
Output:-
Enter number: 25
Fibonacci Series:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368

13. What are structures? How structure elements are accessed and stored.
Ans:-
Structure:
In computer programming, a structure is a composite data type that allows you to group
together related data elements. It is often referred to as a "struct" in many programming
languages. Structures enable you to create custom data types by combining different types of
variables into a single unit.
The elements of a structure, also known as members or fields, can have different data types
such as integers, floating-point numbers, characters, arrays, or even other structures. Each
member within a structure has a unique name and occupies a specific memory location.

To access and store structure elements, you typically use dot notation in most programming
languages. Here's an example to illustrate the concept:
Program:
// Define a structure named "Person"
struct Person {
char name[50];
int age;
float height;
};
int main() {
// Declare a variable of type "Person"
struct Person person1;
// Access and store values in structure elements
strcpy(person1.name, "John Doe");
person1.age = 30;
person1.height = 1.75;
// Access and display structure elements
printf("Name: %s\n", person1.name);
printf("Age: %d\n", person1.age);
printf("Height: %.2f\n", person1.height);
return 0;
}
In the example above, we define a structure called "Person" with three members: `name`,
`age`, and `height`. We declare a variable `person1` of type `Person`. Using dot notation
(`person1.name`, `person1.age`, `person1.height`), we can access and store values in each
structure member.
The data within a structure is stored sequentially in memory, with each member taking up the
appropriate amount of memory based on its data type. The compiler ensures that each
member is properly aligned and accessible within the structure.
It's worth noting that the syntax and specific features related to structures may vary slightly
depending on the programming language you are using. However, the fundamental concept
of grouping related data elements remains consistent across different languages.
14. Create a structure to specify data on students given below : Roll number, Name,
Department, Course, Year of joining Assume that there are not more than 450 students
in the college.
1. Write a function to print names of all students who joined in a particular year.
2. Write a function to print the data of a student whose roll number is received by the
functions
Ans:-
#include<stdio.h>
#include<conio.h>
#include<Windows.h>
struct studata
{
int roll;
char name[50];
char depart[50];
char course[20];
int yoj;
}nos[450] = { 03, "Kishor", "IT", "B.tech", 2014,
10, "Mohammad Siraj Alam", "Computer Science", "B.Tech", 2014,
53, "Deepak", "Computer Applications", "BCA", 2013,
13, "Karan", "Mechanical", "Diploma", 2013,
1, "Aakash", "Tool and Die", "Diploma", 2012,
2, "Ramesh", "IT", "B.tech", 2014
};
void student_in_year(int year)
{
int i;
printf("\n\t\tYear of joining : %d\n\n", year);
for (i = 0; i <= 450; i++)
{
if (nos[i].yoj == year)
{

printf("\nRoll Number : %d", nos[i].roll);


printf("\nName : %s", nos[i].name);
printf("\nDepartment : %s", nos[i].depart);
printf("\nCourse : %s\n", nos[i].course);
}
}
}
void student_data(int enroll)
{
int i;
printf("\nRoll number : %d", enroll);
for (i = 0; i <= 450; i++)
{
if (nos[i].roll == enroll)
{
printf("\nName : %s", nos[i].name);
printf("\nDepartment : %s", nos[i].depart);
printf("\nCourse : %s\n", nos[i].course);
printf("\nYear of joining : %d\n", nos[i].yoj);
}
}
}
int main()
{
int yoj, roll;
printf("\nEnter year of joining of the students : ");
scanf("%d", &yoj);
student_in_year(yoj);
_getch();
system("cls");
printf("\nEnter the roll number of the studnet you want data : ");
scanf("%d", &roll);
student_data(roll);
_getch();
return 0;
}

15. What are pointers? How pointers are defined.


Ans:-
Pointer:
Pointers are variables that store memory addresses. They allow you to indirectly access and
manipulate data by pointing to the memory location where the data is stored. Pointers are
widely used in programming to achieve tasks like dynamic memory allocation, passing
parameters by reference, and working with complex data structures.
To define a pointer, you use the asterisk (*) symbol in most programming languages. Here's
an example in C:
Program:
int main() {
int number = 10; // Declare and initialize an integer variable
int *ptr; // Declare a pointer variable
ptr = &number; // Assign the memory address of 'number' to the pointer
printf("Value of number: %d\n", number);
printf("Address of number: %p\n", &number);
printf("Value of pointer: %p\n", ptr);
printf("Value pointed by pointer: %d\n", *ptr);
return 0;
}
In the code above, we first declare an integer variable called number and assign it a value of
10. We then declare a pointer variable ptr using the asterisk symbol (*). The ptr variable is
capable of storing memory addresses that point to integer values.
To assign the memory address of the number variable to the pointer, we use the ampersand
(&) operator. The expression &number retrieves the address of the number variable, which is
then assigned to ptr.
The output of the program will be:
Output:
Value of number: 10
Address of number: 0x7ffd99d5828c
Value of pointer: 0x7ffd99d5828c
Value pointed by pointer: 10
Here, &number represents the memory address of the number variable, and ptr stores the
same address. The *ptr expression is used to access the value pointed to by the pointer, which
in this case is the value of number.
It's important to note that pointers can be used with different data types, not just integers. You
can have pointers to other variables, structures, arrays, and even functions, depending on the
programming language and its syntax.
Pointer manipulation involves concepts such as dereferencing, pointer arithmetic, and passing
pointers as function arguments, which allow you to perform more advanced operations and
optimize memory usage in your programs.
16. Explain the use of pointers in Self referential structures.
Ans:-
Pointers play a crucial role in self-referential structures, also known as linked data structures.
These structures allow elements within the structure to refer to other elements of the same
type. Pointers are used to establish these connections by storing memory addresses.
One of the most common examples of a self-referential structure is a linked list. In a linked
list, each element, called a node, contains data and a pointer to the next node in the list.
Here's an example in C to illustrate the concept:
Program:
#include <stdio.h>
#include <stdlib.h>
// Define a node structure for a linked list
struct Node {
int data;
struct Node* next;
};
int main( ) {
// Create three nodes
struct Node* node1 = (struct Node*)malloc(sizeof(struct Node));
struct Node* node2 = (struct Node*)malloc(sizeof(struct Node));
struct Node* node3 = (struct Node*)malloc(sizeof(struct Node));
// Assign data and establish connections
node1->data = 10;
node1->next = node2;
node2->data = 20;
node2->next = node3;
node3->data = 30;
node3->next = NULL;
// Traverse and print the linked list
struct Node* current = node1;
while (current != NULL) {
printf("%d ", current->data);
current = current->next;
}
// Free allocated memory
free(node1);
free(node2);
free(node3);
return 0;
}
In the example above, we define a structure called Node that contains an integer data and a
pointer next to the next node in the list. We create three nodes dynamically using malloc()
and assign values to their data members. We then establish connections by assigning the
appropriate memory addresses to the next pointers.
By utilizing pointers, each node knows where the next node in the list is located. This allows
us to traverse the linked list by starting at the first node (node1) and following the next
pointers until we reach the end of the list (where the next pointer is NULL).
Self-referential structures and pointers enable dynamic data structures like linked lists to be
created and modified during runtime, as they provide a flexible way of linking elements
together. Other self-referential structures, such as trees and graphs, also rely on pointers to
establish connections between nodes or vertices.
When working with self-referential structures, it is important to manage memory properly,
allocating and freeing memory as needed to avoid memory leaks. In the example, we use
malloc() to allocate memory for the nodes, and later free() is called to release the allocated
memory.

17. What is Syntax and logical error in compilation.


Ans:- In the context of C programming, syntax and logical errors have similar meanings as
described earlier. Let's define them specifically in relation to C programming:
1. Syntax Error:
- Syntax errors in C occur when the rules of the C language's syntax are violated.
- These errors are detected by the C compiler during the compilation process.
- Examples of syntax errors in C include missing semicolons, mismatched parentheses or
braces, using incorrect format specifiers in printf or scanf statements, or misspelling
keywords.
2. Logical Error:
- Logical errors in C occur when there are flaws or mistakes in the logic or algorithm of the
program, leading to unexpected or incorrect results.
- These errors are not detected by the compiler since the syntax of the program is correct.
- Examples of logical errors in C include using incorrect conditions in if-else statements,
performing incorrect mathematical calculations, using the wrong loop construct, or assigning
values to variables incorrectly.
To differentiate between syntax and logical errors in C:
- Syntax errors are caught by the C compiler during the compilation process and prevent the
successful compilation of the program.
- Logical errors do not cause the compilation to fail, but they result in incorrect program
behavior or unexpected outputs when the program is executed.
To fix syntax errors in C, you need to correct the violations of the C language's syntax rules
by modifying the code to adhere to the correct syntax. On the other hand, fixing logical errors
in C requires identifying and correcting the flawed logic, algorithm, or data manipulation in
the program, which often involves careful code review, debugging techniques, and testing to
find and rectify the logic-related issues.

18. Write a C program to input any alphabet and check whether it is vowel or consonant.
Ans:- C program that takes an input alphabet from the user and checks whether it is a vowel
or a consonant:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
printf("Enter any Alphabet\n"); //input alphabet from user
scanf("%c",&ch);//store the Entered Alphabet in ch
switch(ch)
{
//check lower case vowel letters
case 'a':
printf("%c is a vowel",ch);
break;
case 'e':
printf("%c is a vowel",ch);
break;
case 'i':
printf("%c is a vowel",ch);
break;
case 'o':
printf("%c is a vowel",ch);
break;
case 'u':
printf("%c is a vowel",ch);
break;
//check upper case vowel letters
case 'A':
printf("%c is a vowel",ch);
break;
case 'E':
printf("%c is a vowel",ch);
break;
case 'I':
printf("%c is a vowel",ch);
break;
case 'O':
printf("%c is a vowel",ch);
break;
case 'U':
printf("%c is a vowel",ch);
break;
default:
printf("%c is a consonant",ch);
break;
}
getch();
return 0;
}
Approach

 Define a character variable ch


 The program is asked the user to enter an Alphabets to check whether vowel or consonant
 Entered character is stored in the ch variable
 Define cases for the character ch with vowel character both capital and small
 Next, the program checks every case using the given character.
 Finally, it displays whether the given character is vowel or consonant

19. Write a C program to input month number and print number of days in that month.
Ans:- Certainly! Here's a C program that takes an input month number from the user and
prints the number of days in that month:

```c
#include <stdio.h>

int main() {
int month;

printf("Enter the month number (1-12): ");


scanf("%d", &month);

switch (month) {
case 1:
printf("January has 31 days.\n");
break;
case 2:
printf("February has 28 or 29 days.\n");
break;
case 3:
printf("March has 31 days.\n");
break;
case 4:
printf("April has 30 days.\n");
break;
case 5:
printf("May has 31 days.\n");
break;
case 6:
printf("June has 30 days.\n");
break;
case 7:
printf("July has 31 days.\n");
break;
case 8:
printf("August has 31 days.\n");
break;
case 9:
printf("September has 30 days.\n");
break;
case 10:
printf("October has 31 days.\n");
break;
case 11:
printf("November has 30 days.\n");
break;
case 12:
printf("December has 31 days.\n");
break;
default:
printf("Invalid month number.\n");
break;
}
return 0;
}
```

Explanation:
1. The program prompts the user to enter a month number between 1 and 12.
2. The `scanf` function is used to read the input month number and store it in the variable
`month`.
3. The program uses a switch case statement to check the value of the input month.
4. Cases 1, 3, 5, 7, 8, 10, and 12 are specified as months with 31 days, so if the input matches
any of these cases, the program displays the corresponding message.
5. Case 2 represents February, which can have either 28 or 29 days in a leap year. The
program displays the corresponding message for February.
6. Cases 4, 6, 9, and 11 are specified as months with 30 days, and the program displays the
corresponding message for these months.
7. If the input does not match any of the cases, the default case is executed, and the program
displays an "Invalid month number" message.
8. Finally, the program returns 0 to indicate successful execution.
This program allows the user to input a month number, and it then determines and displays
the number of days in that month.

You might also like