MidTerm
MidTerm
c
Copy
Edit
int a = 5;
int b = 10;
printf("%d", a > b && a != b);
(What is printed? Is the output 1 or 0?)
c
Copy
Edit
int x = 5, y = 0;
if(x = y)
printf("Equal");
else
printf("Not Equal");
c
Copy
Edit
int a = 10;
int b = 20;
if (a = b)
printf("Equal");
else
printf("Not Equal");
c
Copy
Edit
int result;
result = 10 / (5 - 5);
printf("%d", result);
(What runtime error will occur?)
You said:
operator related error and correction questions
ChatGPT said:
Perfect!
Here’s a full set of Operator-Related Error and Correction
Questions for Chapter 2 — focused only on mistakes involving
operators like +, -, *, /, %, =, ==, ++, --, logical operators,
bitwise operators, etc.
c
Copy
Edit
int p = 5;
if(p => 5)
printf("P is greater than or equal to 5\n");
c
Copy
Edit
int a = 10;
if(a !> 5)
printf("Not greater\n");
else
printf("Greater\n");
c
Copy
Edit
int x = 3, y = 7;
if(x && y)
printf("True\n");
else
printf("False\n");
(What exactly does if(x && y) check? Is it comparing values?)
🔹 Increment and Decrement Operators
c
Copy
Edit
int i = 5;
printf("%d", ++i++);
c
Copy
Edit
int a = 10;
printf("%d", a--++);
c
Copy
Edit
int x = 3;
x = ++(x++);
printf("%d", x);
🔹 Bitwise Operators
c
Copy
Edit
int a = 5, b = 9;
int c;
c = a and b;
printf("%d", c);
c
Copy
Edit
int x = 6;
int y = 3;
printf("%d", x xor y);
(Problem: and, xor are not C keywords — C uses & and ^!)
c
Copy
Edit
int x = 5;
int y = 2;
int z = x + y / 2;
printf("%d", z);
(Check: Division happens before addition?)
c
Copy
Edit
int a = 8, b = 4, c = 2;
int r = (a + b) * c / a + b;
printf("%d", r);
(Where brackets change the meaning!)
🔹 Assignment vs Comparison
c
Copy
Edit
int marks = 85;
if(marks = 100)
printf("Full marks!\n");
(Assignment done instead of checking?)
c
Copy
Edit
int a = 10, b = 20;
if(a == b == 0)
printf("Both are zero\n");
(Logical mistake: double comparison confusion!)
🔹 Basics
1.
Write a program to calculate the sum of two integers entered by the user.
2.
Write a program to calculate the area of a rectangle given its length and width.
3.
4.
5.
6.
7.
9.
Write a program to find the remainder when one integer is divided by another.
10.
Write a program to compute the total marks and average marks of 5 subjects.
🔹 Slightly Moderate
11.
Write a program to calculate the compound interest for given Principal, Rate, and Time.
12.
Write a program that takes two integers and displays their sum, difference, product, and division
result (with decimal precision).
13.
14.
15.
Write a program to find the maximum of three numbers using only expressions (no if-else yet).
16.
Write a program that reads two numbers and swaps them without using a temporary variable
(using expressions).
17.
Write a program to convert minutes into hours and minutes (e.g., 130 minutes = 2 hours and 10
minutes).
18.
19.
Write a program that evaluates this expression and shows the result:
(m+n) / (p*q - r)
taking m, n, p, q, and r as inputs.
(Handle if p*q - r == 0.)
20.
Write a program that reads three sides of a triangle and calculates its perimeter and semi-
perimeter.
1.
2.
3.
4.
Differentiate between a declaration statement and an executable statement in C.
5.
Explain the role of a semicolon (;) in C programming. What happens if we omit it after a
statement?
6.
What is the purpose of grouping statements inside curly braces {}? Give an example where it is
necessary.
7.
8.
What is a control statement in C? Classify control statements into categories with examples.
9.
Explain the difference between selection, iteration, and jump control statements in C.
10.
Why are blocks (compound statements) important when writing if-else or loop bodies in C?
Illustrate with an example.
11.
How does C execute multiple statements inside an if block? What happens if we omit curly
braces {}?
12.
Explain the meaning and use of a single-entry, single-exit principle for statements inside blocks.
13.
How can improper placement of semicolons cause logical errors in if-else statements? Explain
with a code example.
14.
15.
Describe how nesting of statements works in C. Give an example using nested if or nested
loops.
16.
What is the role of scope when we declare variables inside compound statements {}? Explain
with an example.
17.
Differentiate between break, continue, and goto statements in C. When would you use each?
18.
Write a short note on the execution flow of statements inside a for loop and explain how
initialization, condition-checking, and updating happen.
19.
Explain with an example how a misplaced else can change the meaning of a C program.
20.
1.
c
CopyEdit
int a = 5
printf("%d", a);
2.
c
CopyEdit
if (a > b)
printf("A is greater");
printf("B is greater");
3.
c
CopyEdit
int a;
a = 10;
b = 20;
printf("%d", a+b);
4.
c
CopyEdit
int x = 10;
if x > 5 {
printf("X is large");
}
5.
c
CopyEdit
for (int i = 0; i < 10; i++)
{
printf("%d", i);
6.
c
CopyEdit
if (x == 10);
{
printf("X is ten");
}
7.
c
CopyEdit
{
int a = 5;
printf("%d", a);
}
printf("%d", a);
8.
c
CopyEdit
if (num % 2 = 0)
{
printf("Even number");
}
9.
c
CopyEdit
int a = 10;
if (a > 5)
printf("Greater");
else
printf("Smaller")
10.
c
CopyEdit
int x = 5;
int y = 10;
if (x > y)
{
printf("X is greater");
}
else
printf("Y is greater")
}
Explain what happens if you miss the semicolon ; after an assignment statement.
12.
What is the error if multiple statements are written inside an if without using {}?
13.
14.
Explain how missing {} can cause logical errors even if there is no compilation error.
15.
c
CopyEdit
{
int a = 5;
}
a = 10;
16.
17.
18.
19.
Explain the effect of missing parentheses () in control statements like if, while, for.
20.
What is the logical error in the following code even though it compiles successfully?
c
CopyEdit
if (x = 0)
printf("Zero");
else
printf("Non-zero");
🔹
Fast Problem Solving – Basic to Moderate
1.
Write a C program to print "YES" if a number is divisible by both 3 and 5, otherwise print "NO".
2.
Given two integers, output the maximum without using any built-in functions like max().
3.
4.
Given an integer n, print "Even" if it is even, otherwise print "Odd", without using modulo
operator %.
5.
Write a program that takes three numbers and prints them in ascending order using only if-else
statements (no arrays).
6.
Given a character input, check if it is a vowel (a, e, i, o, u) or consonant using only if-
else.
7.
Write a C program to find the absolute value of a number without using abs() function.
8.
Given two numbers, swap them without using a third variable.
9.
Write a program that prints numbers from 1 to 100, but for multiples of 3 print "Fizz" instead of
the number, and for multiples of 5 print "Buzz". For numbers which are multiples of both 3 and
5, print "FizzBuzz".
10.
Given an integer n, print "Prime" if it is a prime number, otherwise print "Not Prime". (Use basic
loops and conditions.)
11.
Given two numbers a and b, print the smaller one without using if-else, only using ternary
operator (? :).
12.
13.
Write a C program that reads an integer and prints "Positive", "Negative", or "Zero" based on the
value.
14.
Given a number, check if it lies between 100 and 200 (inclusive) using a single if condition.
15.
Given a number, print "Multiple of 7" if it is a multiple of 7, otherwise print "Not Multiple".
Array related questions
Descriptive Questions (Theory-Based)
1.
2.
3.
What is the importance of index in an array? Why does indexing in C start from 0?
4.
5.
How can you initialize an array at the time of declaration? Give examples for 1D and 2D arrays.
6.
7.
8.
How can you pass a 1D array to a function in C? Write the function signature and explain.
9.
Can you pass a 2D array to a function? How? (Mention what information must be passed.)
10.
11.
What happens if you do not initialize an array in C? How are the elements set?
12.
13.
14.
How is a character array different from an integer array? How are strings handled in C?
15.
16.
How can you find the total number of elements in a 1D array using sizeof operator?
17.
18.
Explain the use of arrays in solving real-life problems. Give two examples.
19.
What is the difference between an array name and a pointer to its first element?
20.
Describe the concept of multi-dimensional arrays (beyond 2D). How are they declared?
1.
c
CopyEdit
int arr[5];
arr[5] = 10;
2.
c
CopyEdit
int arr[] = {1, 2, 3, 4, 5, 6};
printf("%d", arr[6]);
3.
c
CopyEdit
int a[3] = {1, 2};
printf("%d", a[2]);
4.
c
CopyEdit
int arr[2][2];
arr[1,1] = 5;
5.
c
CopyEdit
int arr[3];
scanf("%d", arr[0]);
6.
c
CopyEdit
int a[5];
for(int i=0; i<=5; i++) {
a[i] = i;
}
(Identify and explain the error.)
7.
c
CopyEdit
int arr[3] = {1,2,3,4};
8.
c
CopyEdit
int matrix[2][3] = {{1,2,3},{4,5}};
9.
c
CopyEdit
int arr[3];
printf("%d", *arr[1]);
10.
Explain the problem if you try to assign a full array like this:
c
CopyEdit
int a[3], b[3];
a = b;
2.
3.
Write a C program to reverse an array.
4.
5.
Write a program to input a 3x3 matrix and display the sum of all elements.
6.
Write a program to calculate the row-wise sum and column-wise sum of a 2D array.
7.
8.
Write a C program to transpose a 3x3 matrix (i.e., interchange rows and columns).
9.
10.
11.
12.
Input an array of integers and count how many numbers are even and how many are odd.
13.
14.
Write a program to input 10 numbers and remove duplicates (only unique numbers remain).
15.
16.
17.
18.
19.
Check whether a given matrix is symmetric or not (A matrix is symmetric if A[i][j] == A[j][i]).
20.
1.
c
CopyEdit
int arr[5];
arr[5] = 10;
2.
c
CopyEdit
int arr[];
arr[0] = 10;
c
CopyEdit
int a[3] = {1, 2, 3, 4};
4.
c
CopyEdit
int arr[5] = {1,2};
printf("%d", arr[2]);
5.
c
CopyEdit
int arr[3] = {1,2,3};
printf("%d", arr[3]);
6.
c
CopyEdit
int matrix[2][3] = {1,2,3,4,5,6};
printf("%d", matrix[3][2]);
7.
c
CopyEdit
int matrix[2][2];
matrix[0,1] = 5;
8.
c
CopyEdit
int arr[5];
for(int i = 1; i <= 5; i++)
arr[i] = i * 2;
9.
c
CopyEdit
int arr[3] = {1, 2};
printf("%d", arr[2]);
10.
c
CopyEdit
int arr[4];
scanf("%d", arr[0]);
scanf("%d", arr[1]);
scanf("%d", arr[2]);
scanf("%d", arr[4]);
11.
c
CopyEdit
int a[5];
a = {1,2,3,4,5};
(Why is this assignment wrong?)
12.
c
CopyEdit
int arr[3] = {1,2,3};
arr++;
(Can we do this?)
13.
c
CopyEdit
char str[5] = "Hello";
(What's wrong?)
14.
c
CopyEdit
int matrix[3][2] = {{1,2}, {3,4}, {5}};
printf("%d", matrix[2][1]);
15.
c
CopyEdit
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[-1]);
16.
c
CopyEdit
int a[3] = {1,2,3};
int b[3] = {4,5,6};
a = b;
17.
c
CopyEdit
int arr[2][2];
arr[1][2] = 10;
18.
c
CopyEdit
int arr[5];
printf("%d", arr);
19.
c
CopyEdit
int arr[5];
arr[1] = 10;
printf("%d", arr[1][2]);
20.
c
CopyEdit
int matrix[2][2] = {1,2,3,4,5,6};
(Why is this initialization wrong?)