POP QUESTION BANK
POP QUESTION BANK
1. Define Algorithm. Write an algorithm to find the area and perimeter of a Circle.
Algorithm Definition:
An algorithm is a step-by-step procedure or set of rules to solve a specific problem or
perform a computation. It is a well-defined sequence of instructions that takes input,
processes it, and produces an output.
1. Start.
6. Stop
1. Start.
6. Stop.
Informal way of writing code using plain Formal step-by-step procedure to solve a
English. problem.
Flowchart Definition:
A flowchart is a graphical representation of an algorithm or process. It uses symbols like
rectangles, diamonds, and arrows to represent steps, decisions, and flow of control.
Flowchart:
1. Start.
4. Output SI.
5. Stop.
C Program:
Copy
#include <stdio.h>
int main() {
float P, R, T, SI;
SI = (P * R * T) / 100;
return 0;
1. Preprocessor Directives:
Include header files (e.g., #include <stdio.h>).
2. Main Function:
Entry point of the program (int main()).
3. Variable Declarations:
Declare variables (e.g., int a, b;).
4. Executable Statements:
Perform operations (e.g., a = 10; b = 20;).
5. Return Statement:
End the program (return 0;).
Example:
4. What is a Token? What are the Different Types of Tokens Available in C Language?
Token Definition:
A token is the smallest individual unit in a C program. It can be a keyword, identifier,
constant, string, operator, or symbol.
Types of Tokens in C:
1. Variables:
Used to store data (e.g., int a = 10;).
2. Data Types:
Define the type of data (e.g., int, float, char).
3. Operators:
Perform operations (e.g., +, -, *).
4. Control Structures:
Manage program flow (e.g., if, for, while).
5. Functions:
Reusable blocks of code (e.g., printf(), scanf()).
6. Arrays:
Store multiple values of the same type.
7. Pointers:
Store memory addresses.
6. What is an Identifier (Variable)? What are the Rules to Construct Identifiers?
Identifier Definition:
An identifier is a name given to a variable, function, or other user-defined items. It must be
unique and follow specific rules.
Valid/Invalid Identifiers:
1. num2 - Valid.
4. a_2 - Valid.
6. _apple - Valid.
Variable Definition:
A variable is a named memory location used to store data that can be modified during
program execution.
3. Cannot be a keyword.
Variable Definition:
A variable is a container for storing data values. It has a name, type, and value.
Define:
1. Variable:
A named memory location used to store data.
2. Constant:
A value that cannot be changed during program execution (e.g., const int a = 10;).
3. Associativity:
Determines the order in which operators of the same precedence are evaluated (e.g.,
left-to-right for +).
4. Precedence:
Determines the order in which operators are evaluated (e.g., * has higher
precedence than +).
Constants in C:
Constants are fixed values that do not change during program execution. They can be of
different types:
1. Integer Constants:
Whole numbers without fractional parts.
Example: 10, -5, 0.
2. Floating-Point Constants:
Numbers with fractional parts.
Example: 3.14, -0.5, 2.0.
3. Character Constants:
Single characters enclosed in single quotes.
Example: 'A', '1', '$'.
4. String Constants:
Sequence of characters enclosed in double quotes.
Example: "Hello", "C Programming".
Operators in C:
1. Arithmetic Operators: +, -, *, /, %.
Operator Definition:
An operator is a symbol that performs operations on operands (variables or values).
Types of Operators:
1. Relational Operators:
Used to compare two values.
Example: if (a == b) { /* code */ }.
2. Logical Operators:
Used to combine multiple conditions.
Example: if (a > 0 && b > 0) { /* code */ }.
Assignment Statement:
An assignment statement assigns a value to a variable.
General Form:
variable = expression;
Example: int x = 10;.
10. What are Basic Data Types Available in C? Write the Significance of Each Data Type
Significance:
Write a C Program that Computes the Size of int, float, double, and char Variables
Copy
#include <stdio.h>
int main() {
return 0;
}
11. What is Type Conversion? Explain Two Types of Conversion with Examples
Type Conversion:
The process of converting one data type to another.
1. Implicit Conversion:
Automatically performed by the compiler.
Example: int a = 10; float b = a;.
2. Explicit Conversion:
Manually performed by the programmer using casting.
Example: float a = 10.5; int b = (int)a;.
12. What are the Formatted Input and Output Functions? Explain with Examples
1. printf():
Used to display output.
Example: printf("Hello, World!");.
2. scanf():
Used to take input.
Example: scanf("%d", &num);.
1. printf() Guidelines:
2. scanf() Guidelines:
1. scanf():
Used to read input from the user.
2. printf():
Used to display output to the user.
Copy
#include <stdio.h>
#define PI 3.14159
int main() {
scanf("%f", &radius);
perimeter = 2 * PI * radius;
return 0;
14. Write a Program in C to Print the Numbers from 4 to 9 and Their Squares
Copy
#include <stdio.h>
int main() {
printf("Number\tSquare\n");
printf("%d\t%d\n", i, i * i);
return 0;
Copy
#include <stdio.h>
int main() {
return 0;
16. Write a C Program Which Takes as Input p, t, r. Compute the Simple Interest and
Display the Result
c
Copy
#include <stdio.h>
int main() {
float p, t, r, simple_interest;
simple_interest = (p * t * r) / 100;
return 0;
17. Write a C Program to Find the Area of a Triangle When We Know the Lengths of
All Three of Its Sides
Copy
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, s, area;
s = (a + b + c) / 2; // Semi-perimeter
18. Write a C Program to Find the Largest of Three Numbers Using Ternary Operator
Copy
#include <stdio.h>
int main() {
int a, b, c, largest;
return 0;
MODULE 2
1. List All Conditional Control Statements Used in C. Explain Any Two with Syntax and
Example
1. if statement
2. if-else statement
3. nested if statement
4. else-if ladder
5. switch statement
a) if Statement:
Syntax:
Copy
if (condition) {
Example:
Copy
#include <stdio.h>
int main() {
if (num > 0) {
printf("Number is positive.");
return 0;
b) if-else Statement:
Syntax:
Copy
if (condition) {
} else {
// Code to execute if condition is false
Example:
Copy
#include <stdio.h>
int main() {
if (num > 0) {
printf("Number is positive.");
} else {
return 0;
2. Write a C Program that Reads from the User an Arithmetic Operator and Two
Operands, Perform the Corresponding Arithmetic Operation on the Operands Using
Switch Statement
Copy
#include <stdio.h>
int main() {
char operator;
scanf("%c", &operator);
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
if (num2 != 0)
else
break;
default:
return 0;
Copy
#include <stdio.h>
int main() {
scanf("%d", &num);
original = num;
while (num != 0) {
num /= 10;
if (original == reversed)
else
return 0;
4. What are Unconditional Control Statements? Explain Any Two with Syntax and
Example
1. break
2. continue
3. goto
4. return
a) break Statement:
Syntax:
Copy
break;
Example:
Copy
#include <stdio.h>
int main() {
if (i == 5)
break;
return 0;
b) continue Statement:
Syntax:
Copy
continue;
Example:
Copy
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
if (i == 5)
continue;
return 0;
Copy
#include <stdio.h>
int main() {
int a, b, c;
else
return 0;
Copy
switch (expression) {
case constant1:
break;
case constant2:
break;
default:
Example:
Copy
#include <stdio.h>
int main() {
int day = 3;
switch (day) {
return 0;
}
7. List the Differences Between While Loop and Do-While Loop. Write a C Program to
Find the Sum of Natural Numbers from 1 to N Using For Loop
Differences:
C Program:
Copy
#include <stdio.h>
int main() {
int n, sum = 0;
scanf("%d", &n);
sum += i;
return 0;
8. Write a C Program to Find the Factorial of a Number Using Do-While, Where the
Number N is Entered by the User
Copy
#include <stdio.h>
int main() {
int n, factorial = 1;
scanf("%d", &n);
int i = 1;
do {
factorial *= i;
i++;
return 0;
9. What is Two-Way Selection Statement? Explain if, if-else, and Cascaded if-else with
Examples
a) if Statement:
Example:
Copy
b) if-else Statement:
Example:
Copy
} else {
Example:
Copy
printf("Grade: A");
printf("Grade: B");
printf("Grade: C");
} else {
printf("Grade: D");
10. Write a C Program that Takes from User an Arithmetic Operator (+, -, *, or /) and
Two Operands. Perform Corresponding Arithmetic Operation on the Operands Using
Switch Statement
Copy
#include <stdio.h>
int main() {
char operator;
scanf("%c", &operator);
switch (operator) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
if (num2 != 0)
else
break;
default:
return 0;
}
11. Explain with Example, the Meaning of Statement and Block in a C Program
Statement:
A statement is a single instruction in a C program that performs a specific task. It ends
with a semicolon (;).
Example:
Copy
printf("Hello"); // Statement
Block:
A block is a group of statements enclosed in curly braces {}. It is treated as a single unit.
Example:
Copy
int a = 10;
printf("%d", a);
Copy
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if (num <= 0) {
return 0;
end:
return 0;
13. Explain with Syntax, if, if-else, and Nested if-else Statements in C Program
a) if Statement:
Syntax:
Copy
if (condition) {
Example:
Copy
b) if-else Statement:
Syntax:
Copy
if (condition) {
} else {
Example:
Copy
printf("Passed.");
} else {
printf("Failed.");
Syntax:
Copy
if (condition1) {
} else if (condition2) {
} else {
Example:
c
Copy
printf("Grade: A");
printf("Grade: B");
} else {
printf("Grade: C");
a) for Loop:
Syntax:
Copy
// Code to execute
Example:
Copy
b) while Loop:
Syntax:
Copy
while (condition) {
// Code to execute
Example:
Copy
int i = 1;
while (i <= 5) {
i++;
c) do-while Loop:
Syntax:
Copy
do {
// Code to execute
} while (condition);
Example:
Copy
int i = 1;
do {
i++;
Copy
#include <stdio.h>
int main() {
int n, sum;
scanf("%d", &n);
return 0;
16. Write a C Program that Takes Three Coefficients (a, b, and c) of a Quadratic
Equation (ax^2 + bx + c) as Input and Compute All Possible Roots and Print Them with
Appropriate Messages
Copy
#include <stdio.h>
#include <math.h>
int main() {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
printf("Roots are real and different: %.2f and %.2f", root1, root2);
} else if (discriminant == 0) {
root1 = -b / (2 * a);
} else {
printf("Roots are complex: %.2f + %.2fi and %.2f - %.2fi", realPart, imaginaryPart,
realPart, imaginaryPart);
return 0;
17. Show How break and continue Statements Are Used in a C Program, with Example
a) break Statement:
Example:
Copy
#include <stdio.h>
int main() {
if (i == 5)
return 0;
b) continue Statement:
Example:
Copy
#include <stdio.h>
int main() {
if (i == 5)
return 0;
a) printf():
Example:
Copy
printf("Hello, World!\n");
b) scanf():
Example:
c
Copy
int num;
scanf("%d", &num);
19. Write a C Program to Find GCD of Two Numbers Using Ternary Operator and For
Loop
Copy
#include <stdio.h>
int main() {
return 0;
Copy
#include <stdio.h>
int main() {
char operator;
scanf("%c", &operator);
switch (operator) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
if (num2 != 0)
else
break;
default:
return 0;
}
21. What is Dangling Else Problem? Explain How to Handle It in C Programming
Example:
Copy
if (condition1)
if (condition2)
printf("Condition2 is true");
else
Solution:
Use braces {} to explicitly define the scope of if and else.
Corrected Code:
Copy
if (condition1) {
if (condition2) {
printf("Condition2 is true");
} else {
printf("Condition1 is false");
MODULE 3
1. What is an Array? Explain the Declaration and Initialization of One-Dimensional and
Two-Dimensional Arrays with an Example
Array Definition:
An array is a collection of elements of the same data type stored in contiguous memory
locations. It allows storing multiple values under a single variable name.
a) One-Dimensional Array:
Declaration:
Copy
data_type array_name[size];
Initialization:
Copy
b) Two-Dimensional Array:
Declaration:
Copy
data_type array_name[row_size][column_size];
Initialization:
Copy
data_type array_name[row_size][column_size] = {
...
};
2. Write a C Program to Read N Integers into an Array A and to Find the (i) Sum of Odd
Numbers, (ii) Sum of Even Numbers, (iii) Average of All Numbers
Copy
#include <stdio.h>
int main() {
float average;
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
total_sum += A[i];
if (A[i] % 2 == 0)
sum_even += A[i];
else
sum_odd += A[i];
}
average = (float)total_sum / n;
return 0;
a) Linear Search:
Copy
#include <stdio.h>
int main() {
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
scanf("%d", &key);
for (int i = 0; i < n; i++) {
if (A[i] == key) {
found = 1;
break;
if (!found)
return 0;
b) Binary Search:
Copy
#include <stdio.h>
int main() {
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
}
scanf("%d", &key);
low = 0;
high = n - 1;
if (A[mid] == key) {
found = 1;
break;
low = mid + 1;
} else {
high = mid - 1;
if (!found)
return 0;
Copy
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
// Bubble Sort
A[j + 1] = temp;
printf("Sorted array:\n");
for (int i = 0; i < n; i++) {
return 0;
b) Linear Search:
Copy
#include <stdio.h>
int main() {
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
scanf("%d", &key);
if (A[i] == key) {
break;
if (!found)
return 0;
Copy
#include <stdio.h>
int main() {
int n, sum = 0;
float average;
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
sum += A[i];
}
average = (float)sum / n;
return 0;
Copy
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
return 0;
Copy
#include <stdio.h>
int main() {
int A[rows][cols];
scanf("%d", &A[i][j]);
greatest = A[i][j];
return 0;
Copy
#include <stdio.h>
A[j + 1] = temp;
}
}
int main() {
int n;
scanf("%d", &n);
int A[n];
scanf("%d", &A[i]);
bubbleSort(A, n);
printf("Sorted array:\n");
return 0;
9. Define String. How String is Declared and Initialized? Explain String Input/Output
Functions with an Example
String Definition:
A string is a sequence of characters stored in contiguous memory locations, terminated
by a null character (\0).
Declaration and Initialization:
Copy
Copy
char str[100];
Copy
char str[100];
Copy
char str[100];
Copy
Example:
Copy
#include <stdio.h>
int main() {
char str[100];
return 0;
10. What is a String? Write a C Program that Reads a Sentence and Prints the
Frequency of Each of the Vowels and Total Count of Consonants
String Definition:
A string is a sequence of characters terminated by a null character (\0).
C Program:
Copy
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
char ch = tolower(str[i]);
printf("Frequency of vowels:\n");
return 0;
11. Write a C Program to Eliminate Multiple Spaces from a Sentence and Make It Single
Copy
#include <stdio.h>
int main() {
int i = 0, j = 0;
result[j++] = str[i];
i++;
result[j] = '\0';
return 0;
12. Explain with Syntax and Example, the Different String Manipulation Library
Functions
Copy
Example:
Copy
Copy
Copy
char dest[10];
strcpy(dest, src);
Copy
Example:
Copy
strcat(str1, str2);
Copy
Example:
Copy
if (strcmp(str1, str2) == 0)
printf("Strings are equal.\n");
else
13. Define String. List Out All String Manipulation Functions. Explain Any Two with
Example
String Definition:
A string is a sequence of characters terminated by a null character (\0).
1. strlen()
2. strcpy()
3. strcat()
4. strcmp()
5. strchr()
6. strstr()
7. strrev()
Copy
#include <stdio.h>
#include <string.h>
int main() {
char str2[10];
strcpy(str2, str1);
Copy
#include <stdio.h>
int i = 0;
dest[i] = src[i];
i++;
dest[i] = '\0';
int main() {
char str2[10];
STRCOPY(str2, str1);
return 0;
15. Write a Program to Replace Each Constant in a String with the Next One Except
Letters 'z', 'Z', 'a', 'A'
c
Copy
#include <stdio.h>
int main() {
if ((str[i] >= 'b' && str[i] <= 'y') || (str[i] >= 'B' && str[i] <= 'Y')) {
str[i]++;
return 0;
Copy
#include <stdio.h>
int i = 0, j = 0;
dest[i++] = src[j++];
dest[i] = '\0';
}
int main() {
CONCAT(str1, str2);
return 0;
17. Explain with Example (i) Character String (ii) String Literal (iii) Storage Classes
a) Character String:
Copy
b) String Literal:
Copy
printf("Hello");
c) Storage Classes:
Copy
Functions:
1. strlen()
2. strcpy()
3. strcat()
4. strcmp()
Examples:
Copy
#include <stdio.h>
#include <string.h>
int main() {
char str2[10];
return 0;
}
19. Write a C Program to Check Whether the Given String is Palindrome or Not Without
Using In-Built Function
Copy
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
flag = 0;
break;
if (flag)
else
return 0;
}
20. Write a C Program to Search a Name in a Given List Using Binary Search Technique
Copy
#include <stdio.h>
#include <string.h>
int main() {
int n = 5;
char key[20];
scanf("%s", key);
if (strcmp(names[mid], key) == 0) {
found = 1;
break;
low = mid + 1;
} else {
high = mid - 1;
}
if (!found)
return 0;
MODULE 4
1. What is a Function? Explain the Difference Between User-Defined and Library Functions
Function Definition:
A function is a block of code that performs a specific task. It can take inputs, process them,
and return a result.
Must be declared and defined before use. Already declared and defined in headers.
Copy
2. Function Definition:
Implements the function's logic.
c
Copy
return a + b;
3. Function Call:
Invokes the function to execute its code.
Copy
Function Definition:
Copy
#include <stdio.h>
return a + b;
int main() {
return 0;
}
4. Explain Two Categories/Types of Argument Passing Techniques, with Examples
a) Call by Value:
Example:
Copy
#include <stdio.h>
void increment(int x) {
x++;
int main() {
int num = 5;
return 0;
b) Call by Reference:
Example:
Copy
#include <stdio.h>
(*x)++;
printf("Inside function: %d\n", *x); // Output: 6
int main() {
int num = 5;
return 0;
Copy
void greet() {
printf("Hello, World!\n");
Copy
Copy
int getNumber() {
return 10;
Copy
return a + b;
6. Write a C Function isprime(num) that Accepts an Integer Argument and Returns 1 if the
Argument is a Prime or 0 Otherwise. Write a Program that Invokes this Function to
Generate Prime Numbers Between the Given Ranges
Copy
#include <stdio.h>
return 1; // Prime
int main() {
if (isprime(i)) {
return 0;
7. Write a program in C using functions to swap two numbers using global variables and
call by reference concept.
Copy
#include <stdio.h>
void swap() {
int temp = a;
a = b;
b = temp;
int main() {
swap();
return 0;
Copy
#include <stdio.h>
*x = *y;
*y = temp;
int main() {
int a, b;
swap(&a, &b);
return 0;
8. What are actual parameters and formal parameters? Illustrate with an example.
• Actual Parameters: These are the values or variables passed to a function when it is
called.
• Formal Parameters: These are the variables defined in the function definition to
receive the values of the actual parameters.
Example:
Copy
#include <stdio.h>
int main() {
int a = 5, b = 10;
return 0;
Copy
#include <stdio.h>
int factorial(int n) {
int fact = 1;
fact *= i;
}
return fact;
int main() {
int num;
scanf("%d", &num);
return 0;
10. Write a program to find GCD and LCM of two numbers using functions.
Copy
#include <stdio.h>
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
return a;
}
int main() {
return 0;
2. Static Variable: Scope is local to the block, lifetime is the entire program execution.
3. Automatic Variable: Scope is local to the block, lifetime is within the block.
4. Register Variable: Scope is local to the block, lifetime is within the block (stored in
CPU registers).
13. What is Recursion? Write a C program to compute polynomial coefficient nCr using
recursion.
Recursion:
Copy
#include <stdio.h>
int factorial(int n) {
if (n == 0 || n == 1) return 1;
int main() {
int n, r;
return 0;
14. Define recursion. Write a C recursive function for multiplying two integers.
Recursive Multiplication:
Copy
#include <stdio.h>
if (n == 0) return 0;
int main() {
int a, b;
return 0;
Copy
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
else
printf("%d is not prime.\n", num);
return 0;
Copy
#include <stdio.h>
int factorial(int n) {
if (n == 0 || n == 1) return 1;
int main() {
int num;
scanf("%d", &num);
return 0;
17. Explain recursion and write a program to find the nth term of the Fibonacci series.
Recursion:
Recursion is a technique where a function calls itself to solve smaller instances of the same
problem.
Fibonacci Series:
c
Copy
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1) return n;
int main() {
int n;
scanf("%d", &n);
return 0;
MODULE 5
1. What is a Structure? Explain the C Syntax of Structure Declaration with an Example
Structure is a user-defined data type in C that allows you to combine data items of different
kinds. Structures are used to represent a record.
Syntax:
Copy
struct structure_name {
data_type member1;
data_type member2;
...
};
Example:
Copy
#include <stdio.h>
struct Student {
int roll_no;
char name[50];
float marks;
char grade;
};
int main() {
s1.roll_no = 1;
s1.marks = 95.5;
s1.grade = 'A';
return 0;
Example:
Copy
struct Student {
int roll_no;
char name[50];
float marks;
char grade;
};
Example:
Copy
struct Date {
int day;
int month;
int year;
};
struct Student {
int roll_no;
char name[50];
float marks;
char grade;
};
Copy
#include <stdio.h>
#include <string.h>
struct Student {
int roll_no;
char name[50];
float marks;
char grade;
};
int main() {
int n, i;
char search_name[50];
scanf("%d", &n);
printf("Name: ");
scanf("%s", students[i].name);
printf("Marks: ");
scanf("%f", &students[i].marks);
printf("Grade: ");
scanf("%s", search_name);
if (strcmp(students[i].name, search_name) == 0) {
break;
if (i == n) {
return 0;
Copy
#include <stdio.h>
struct Student {
int roll_no;
char name[50];
float marks;
char grade;
};
int main() {
printStudent(s1);
return 0;
5. Write a C Program to Store and Print Name, USN, Subject, and IA Marks of Students
Using Structure
Copy
#include <stdio.h>
struct Student {
char name[50];
char usn[20];
char subject[50];
float ia_marks;
};
int main() {
return 0;
• Array:
• Structure:
Example:
c
Copy
#include <stdio.h>
typedef struct {
int roll_no;
char name[50];
float marks;
char grade;
} Student;
int main() {
return 0;
Copy
#include <stdio.h>
struct Employee {
int id;
char name[50];
float salary;
};
int main() {
int n, i;
scanf("%d", &n);
printf("ID: ");
scanf("%d", &employees[i].id);
printf("Name: ");
scanf("%s", employees[i].name);
printf("Salary: ");
scanf("%f", &employees[i].salary);
return 0;
9. What is a Pointer? Explain How the Pointer Variable is Declared and Initialized
Declaration:
Copy
data_type *pointer_name;
Initialization:
Copy
int a = 10;
Example:
Copy
#include <stdio.h>
int main() {
int a = 10;
int *p = &a;
return 0;
10. Explain the Array of Pointers with Example or Explain How Pointers and Arrays Are
Related with Example
Array of Pointers:
An array of pointers is an array where each element is a pointer to a variable of a specific
type. This is commonly used to store strings or dynamically allocated memory.
Example:
Copy
#include <stdio.h>
int main() {
int i;
return 0;
Example:
c
Copy
#include <stdio.h>
int main() {
printf("Element %d: %d\n", i + 1, *(ptr + i)); // Accessing array elements using pointer
return 0;
11. What is a Pointer? Write a C Program to Find the Sum and Mean of All Elements in an
Array Using Pointer
Pointer:
A pointer is a variable that stores the memory address of another variable.
Program:
Copy
#include <stdio.h>
int main() {
int sum = 0;
float mean;
for (int i = 0; i < n; i++) {
mean = (float)sum / n;
return 0;
12. Write a C Program to Swap Two Numbers Using Call by Address (Pointers or Reference)
Method
Program:
Copy
#include <stdio.h>
*a = *b;
*b = temp;
int main() {
return 0;
13. Write a C Program Using Pointers to Compute the Sum, Mean, and Standard Deviation
of All Elements Stored in an Array of 'n' Real Numbers
Program:
Copy
#include <stdio.h>
#include <math.h>
int main() {
// Calculate sum
// Calculate mean
mean = sum / n;
// Calculate variance
variance /= n;
std_deviation = sqrt(variance);
return 0;
14. What is a Pointer? Give the Advantages and Disadvantages of Pointer Data Type
Pointer:
A pointer is a variable that stores the memory address of another variable. It allows direct
access to memory locations, enabling dynamic memory allocation, efficient array handling,
and more.
Advantages of Pointers:
2. Efficient Array Handling: Pointers provide efficient access to array elements using
pointer arithmetic.
Disadvantages of Pointers:
2. Memory Leaks: Improper use of pointers can lead to memory leaks if dynamically
allocated memory is not freed.
3. Dangling Pointers: Pointers can become invalid if they point to memory that has
been deallocated.
4. Security Risks: Pointers can lead to security vulnerabilities like buffer overflows if not
handled carefully.
Copy
#include <stdio.h>
int main() {
int a = 10;
return 0;