Question 1
Suppose you have two 8-bit binary numbers, A and B, represented as (00010101)2 and (00000110)2, respectively. Perform the subtraction A−B and determine the decimal equivalent of the result.
19
15
21
6
The IIT Madras BS Introduction to C Programming (Intro to C Programming) Qualifier paper sat on 1 Sept 2024, in the May 2024 term: 16 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
Suppose you have two 8-bit binary numbers, A and B, represented as (00010101)2 and (00000110)2, respectively. Perform the subtraction A−B and determine the decimal equivalent of the result.
19
15
21
6
Correct answer
15
Consider the following algorithm where number n stored in register R1, and the final result stored in register R2.
1. R1 = n
2. R2 = 1
3. R2 = R2 * R1
4. R1 = R1 - 1
5. If R1 > 0, go to step 3, otherwise go to step 6.
6. Print(R2)
Which of the following statements represents the correct purpose of the given algorithm?
The algorithm calculates the sum of all numbers from 1 to n.
The algorithm calculates the power of 2 raised to n.
The algorithm calculates the nth Fibonacci number.
The algorithm calculates the factorial of the number n.
Correct answer
The algorithm calculates the factorial of the number n.
Consider the below C program.
#include <stdio.h>
int main() { int n = 10; int i = 0, j = 1; while (i < n) { printf("%d ", i); i += j; j++; } return 0;}What will be the output of the above program?
0 1 2 3 4 5 6 7 8 9
0 1 3 6
0 2 4 8
1 3 6 10
Correct answer
0 1 3 6
Consider the below C program.
#include <stdio.h>
int main() { int x = 1, y = 2, z = 0; if (z == 1) y++; x--;
if (x > 1) x--; z++;
printf("%d %d %d", x, y, z); return 0;}What will be the output of the above program?
0 3 0
0 2 1
1 2 0
1 2 1
Correct answer
0 2 1
Consider the below C program.
#include <stdio.h>
int main() { int x = 5, y = 3, z = 7; int result = (x > y) && (y < z);
printf("%d\n", result); return 0;}What will be the output of the above program?
0
1
2
3
Correct answer
1
Consider the following mathematical expression in C language:
result = (a + b) * (c - d) / (e * f);
Determine the number of primitive operations required to evaluate this expression.
5
6
4
7
Correct answer
5
Find the decimal equivalent for the unsigned binary representation (10100110)2.
168
166
170
162
Correct answer
166
Given an 8-bit binary number (11010100)2, what is its representation in two's complement notation?
(01101000)2
(00101111)2
(00101100)2
(10101000)2
Correct answer
(00101100)2
Find the hexadecimal equivalent of the binary representation (1101 1011 0011 1011 1110 1010)2.
DD3B7A
DBB6FA
DB6FAB
DB3BEA
Correct answer
DB3BEA
Given the ASCII value of the character '0' is 48 and the ASCII value of the character '9' is 57, what is the sum of the ASCII values of all characters from '0' to '9'?
435
535
430
525
Correct answer
525
Consider the below C program.
#include <stdio.h>
int main() { int x = 5; int y = 3; int z = 2; int result = x + y * z - x / z; printf("%d\n", result); return 0;}What will be the output of the above program?
5
5.5
9
9.5
Correct answer
9
Consider the below C program.
#include <stdio.h>
int main() { int a = 10, b = 20, c = 30; b++ > 20 ? a-- : ++c; printf("%d %d %d", a, b, c); return 0;}What will be the output of the above program?
10 20 30
9 21 31
10 21 31
10 20 31
Correct answer
10 21 31
Which of the following is true about the “sizeof” operator in C?
It returns the number of elements in an array.
It returns the size of a variable in bytes.
It returns the size of a variable in bits.
It returns the memory address of a variable.
Correct answer
It returns the size of a variable in bytes.
Which of the following is not a valid data type in C?
float
map
char
double
Correct answer
map
Which of the following is used to terminate a C statement?
Period (.)
Colon (:)
Comma (,)
Semicolon (;)
Correct answer
Semicolon (;)
Which of the following can be used as identifier(s) in C language?
Correct answers