C Questions
C Questions
Bitwise Representation:
• 1000 (A)
• 0100 (B)
2. A | B (Bitwise OR):
• 1000 (A)
• 0100 (B)
3. A ^ B (Bitwise XOR):
• 1000 (A)
• 0100 (B)
Summary:
• A&B=0
• A | B = 12
• A ^ B = 12
Linker:
A linker combines object files and external libraries into a single executable. It resolves
function/variable references and assigns memory addresses to code and data.
Loader:
A loader loads the executable into memory, allocates memory, adjusts addresses (if needed), and
starts the program’s execution.
Summary:
• Linker: Combines and resolves code for execution.
• Control Flow:
• Performance:
• Readability:
1(e) How one- and two-dimensional subscripted variables (arrays) are declared?
One-Dimensional Arrays:
Two-Dimensional Arrays:
A two-dimensional array is essentially an array of arrays, allowing for the representation of a table or
matrix.
PART-B
2(a) Make use of conditional operators in C and write a program to determine the largest value
among three positive integer numbers.
#include <stdio.h>
int main() {
int a, b, c;
return 0;
Explanation:
1. Input: The program prompts the user to enter three positive integers.
Example
5 12 8
X=A/B*C-B+A*D/3
Y=A+B*C+(D*E)+F*G
Step-by-Step Evaluation:
1. Calculate AB\frac{A}{B}BA:
3. Subtract BBB:
5. Divide by 3:
So,
Step-by-Step Evaluation:
So,
Y=69Y = 69Y=69
Final Results:
• X ≈ 0.8333
• Y = 69
3(a) Differentiate between entry-control and exit control loops with example
1. Entry-Control Loops:
Entry-control loops check the loop condition before executing the loop body. If the condition is false
from the beginning, the loop body is never executed.
• Examples:
o for loop
o while loop
#include <stdio.h>
int main() {
int i = 0;
while (i < 5) {
printf("%d\n", i);
i++;
return 0;
2. Exit-Control Loops:
Exit-control loops check the loop condition after executing the loop body. This guarantees that the
loop body is executed at least once, even if the condition is false.
• Example:
o do...while loop
#include <stdio.h>
int main() {
int i = 5;
do {
printf("%d\n", i);
i++;
return 0;
}
Summary of Differences:
Condition Check Before executing the loop body After executing the loop body
Execution Guarantee May not execute if condition is false Always executes at least once
3(b) Write a C program to print. and explain the looping concepts used in it.
1
12
123
1234
12345
#include <stdio.h>
int main() {
int i, j, rows = 5;
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
OUTPUT:
1
12
123
1234
12345
Summary:
• The program uses nested loops where the outer loop determines the number of rows, and
the inner loop controls the number of printed numbers in each row.
• This structure allows for a clear and organized way to build the desired pattern through
controlled iterations.
#include <stdio.h>
#define MAX 10
int main() {
scanf("%d", &matrix1[i][j]);
scanf("%d", &matrix2[i][j]);
printf("\n");
return 0;
OUTPUT:
68
10 12
#include <stdio.h>
int main() {
int arr[100], n;
int count = 0;
int sum = 0;
scanf("%d", &n);
printf("Enter %d elements:\n", n);
scanf("%d", &arr[i]);
if (arr[i] % 2 == 0) {
count++;
sum += arr[i];
return 0;
OUTPUT:
Enter 5 elements:
Element [1]: 1
Element [2]: 2
Element [3]: 3
Element [4]: 4
Element [5]: 5
4. Determinism: Always gives the same output for the same input.
A compiler in C is a program that translates the source code written in C into machine code (binary)
that a computer can execute. It checks for syntax errors and optimizes the code during this process.
Compilation is the process of converting C source code into an executable file. It involves multiple
stages: preprocessing, compilation, assembly, and linking, transforming the human-readable code
into machine-readable instructions
Void main() {
int num;
scanf("%d", &num);
if (num % 2 == 0) {
else {
(d) What is the difference between while loop and do…while loop?
The main difference between a while loop and a do...while loop is:
• While Loop:
o The loop may not execute at all if the condition is false initially.
• Do...While Loop:
o The loop body is executed at least once, as the condition is checked after executing
the loop.
In C, you can access elements of an array using the index of the element, starting from 0 for the first
element. The syntax is array_name[index], where index is the position of the element you want to
access.
#include <stdio.h>
int main() {
numbers[1] = 25;
return 0;
PART-B
2(a) Write the importance of precedence and associativity? Write the table for operator precedence?
• Associativity defines the order in which operators of the same precedence level are
processed. It can be either left-to-right or right-to-left.
2(b) What is meant by type conversion? Why is necessary? Explain about implicit and explicit type
conversion with examples.
Type conversion is the process of converting a value from one data type to another. In C, it occurs
when an expression or variable of one type needs to be interpreted or used as another type.
o The conversion follows predefined rules, typically promoting smaller types to larger
types (e.g., converting int to float) to avoid data loss.
Example:
int x = 10;
float y = 5.5;
float result = x + y;
In this example, x (int) is implicitly converted to float to perform the addition with y.
• It’s used when precise control over the conversion is needed or when automatic conversion
could lead to incorrect results or data loss.
Example:
float x = 9.7;
this example, the float x is explicitly cast to an integer, truncating the decimal part.
Summary:
• Explicit type conversion requires the programmer to manually specify the new type using
casting.
3(a) Select an appropriate method and write a C program that validates whether a given integer is a
palindrome.
To validate whether a given integer is a palindrome, we can reverse the digits of the number and
check if the reversed number is the same as the original number.
#include <stdio.h>
int main() {
scanf("%d", &num);
originalNum = num;
while (num != 0) {
num /= 10;
if (originalNum == reversedNum) {
} else {
return 0;
Explanation:
2. The program stores the original number and then reverses it by extracting digits one by one.
3. After reversing the number, it compares the reversed number with the original one.
Example:
• Input: 121
• Input: 123
3(b) Write a program using do-while loop to read the numbers until -1 and also
count the positive, negative and zeros encountered by the users.
#include <stdio.h>
int main() {
int number;
do {
scanf("%d", &number);
if (number > 0) {
positiveCount++;
negativeCount++;
} else if (number == 0) {
zeroCount++;
return 0;
Explanation:
1. The program initializes counters for positive, negative, and zero values.
2. A do-while loop prompts the user to enter numbers repeatedly until -1 is entered.
3. Inside the loop, the program checks the value of each number and updates the respective
counters accordingly.
4. After exiting the loop, the program prints the counts of positive numbers, negative numbers,
and zeros.
Positive numbers: 2
Negative numbers: 1
Zeros: 1
4(a) Solve the problem of finding the largest element in an array using a C program.
#include <stdio.h>
int main() {
int n, i, largest;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
}
largest = arr[0];
largest = arr[i];
return 0;
Explanation:
1. The program prompts the user to enter the size of the array.
2. It initializes an array of that size and reads the elements from the user.
3. It assumes the first element of the array is the largest and then iterates through the rest of
the array.
4. If it finds an element larger than the current largest, it updates the largest variable.
Enter 5 elements:
Element 1: 10
Element 2: 5
Element 3: 20
Element 4: 15
Element 5: 30
int main() {
if (col1 != row2) {
printf("Matrix multiplication not possible. Number of columns in the first matrix must equal the
number of rows in the second matrix.\n");
return 1;
scanf("%d", &matrix1[i][j]);
scanf("%d", &matrix2[i][j]);
result[i][j] = 0;
printf("\n");
return 0;
Explanation:
1. The program first prompts the user for the dimensions of the two matrices.
2. It checks if the multiplication is possible by comparing the number of columns in the first
matrix to the number of rows in the second matrix.
4. A result matrix is initialized to zero, and the program computes the multiplication using three
nested loops:
o The outer two loops iterate over the rows of the first matrix and the columns of the
second matrix.
o The innermost loop calculates the dot product for each element in the resulting
matrix.
Element [1][1]: 1
Element [1][2]: 2
Element [1][3]: 3
Element [2][1]: 4
Element [2][2]: 5
Element [2][3]: 6
Element [1][1]: 7
Element [1][2]: 8
Element [2][1]: 9
Element [2][2]: 10
Element [3][1]: 11
Element [3][2]: 12
58 64
139 154