Quiz Space

May 2024 term · Introduction to C Programming · CS1101

Intro to C Programming End Term: 1 September 2024, Set QEF3 (May 2024 term)

The IIT Madras BS Introduction to C Programming (Intro to C Programming) End Term paper sat on 1 Sept 2024, in the May 2024 term, set QEF3: 25 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
25
Marks
100
Duration
180 min
MSQ
4
MCQ
19
Numerical
2

Updated

Official paper: IIT M ES FOUNDATION AN EXAM QEF3 01 Sep 2024 · No negative marking.

Question 1

+3 marksOne or more correct options

Which of the following statements is/are true about the switch statement in C?

Select all that apply.

  1. A

    The break statement is compulsory to use with switch statement.

  2. B

    The default statement is compulsory to use with switch statement.

  3. C

    The default statement is optional with switch statement.

  4. D

    Multiple case labels can be used with switch statement.

Show answer

Correct answers

  • C

    The default statement is optional with switch statement.

  • D

    Multiple case labels can be used with switch statement.

Question 2

+3 marksOne or more correct options

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • A
  • C

Question 3

+3 marksOne correct option

Which of the following statements correctly declares a pointer variable ptr to hold the address of a character variable ch in C and assigns the address of ch to ptr?

  1. A

    char *ptr; ptr = &ch;

  2. B

    char *ptr; ptr = *ch;

  3. C

    char ptr; ptr = &ch;

  4. D

    char ptr; ptr = *ch;

Show answer

Correct answer

  • A

    char *ptr; ptr = &ch;

Question 4

+3 marksOne correct option

Which of the following functions is used in C to allocate memory dynamically during runtime?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 5

+3 marksOne correct option

Which of the following statement is true about structures and unions in C regarding memory allocation?

  1. A

    Structures allocate memory based on the sum of all member sizes.

  2. B

    Unions allocate memory based on the sum of all member sizes.

  3. C

    Memory is shared between members in the structures.

  4. D

    Unions and structures allocate memory in the same way.

Show answer

Correct answer

  • A

    Structures allocate memory based on the sum of all member sizes.

Question 6

+3 marksOne correct option

Which memory region in C programming is used for storing dynamically allocated memory?

  1. A

    Heap memory

  2. B

    Stack memory

  3. C

    Pointer Segment

  4. D

    Data segment

Show answer

Correct answer

  • A

    Heap memory

Question 7

+3 marksOne correct option

Which function is used to read data from a file in C programming?

  1. A

    fread()

  2. B

    fget()

  3. C

    read()

  4. D

    get()

Show answer

Correct answer

  • A

    fread()

Question 8

+3 marksOne correct option

In C preprocessor directives, what does the # operator do when used in macro definitions?

  1. A

    Excludes a token

  2. B

    Concatenates two tokens

  3. C

    Multiplies two tokens

  4. D

    Converts a token to a string

Show answer

Correct answer

  • D

    Converts a token to a string

Question 9

+4 marksOne correct option

Consider the below C program

c
#include <stdio.h>
int main() {
int a = 5, b = 15, c = 2;
switch(b % a) {
case 0: c = c + a + b;
break;
case 1: c = c * a * b;
case 2: c = c - a - b;
break;
default: c = c / a / b;
}
printf("Value of c: %d", c);
return 0;
}

What will be the output of the above C program?

  1. A

    Value of c: 22

  2. B

    Value of c: 150

  3. C

    Value of c: 0

  4. D

    Value of c: 0.33

Show answer

Correct answer

  • A

    Value of c: 22

Question 10

+4 marksOne correct option

What is the order in which the functions are called in the following C program?

c
#include <stdio.h>
#include <math.h>
int square(int x){
return x*x;
}
double area(double radius){
return 3.14 * square(radius);
}
int main(){
printf("%.2f", area(4));
}
  1. A

    main → printf → area → square

  2. B

    main → area → printf → square

  3. C

    main → area → square → printf

  4. D

    main → square → area → printf

Show answer

Correct answer

  • C

    main → area → square → printf

Question 11

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
int main() {
char s[30] = "Hello World";
char *p = &s[6];
p = p - 2;
printf("%s", p);
return 0;
}

What will be the output of the above C program?

  1. A

    Hello

  2. B

    Hello World

  3. C

    llo World

  4. D

    o World

Show answer

Correct answer

  • D

    o World

Question 12

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
int main() {
char a[20] = {'a', 'b', 'c', 'd', [9] = 'e', 'f', 'g'};
printf("%c", a[10]);
return 0;
}

What will be the output of the above C program?

  1. A

    d

  2. B

    e

  3. C

    f

  4. D

    g

Show answer

Correct answer

  • C

    f

Question 13

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
enum colors{Red, Green, Blue = 5, Yellow};
int main() {
enum colors a = Green;
printf("%d", a+Yellow);
return 0;
}

What will be the output of the above C program?

  1. A

    5

  2. B

    6

  3. C

    7

  4. D

    8

Show answer

Correct answer

  • C

    7

Question 14

+4 marksOne correct option

Consider the following C program.

c
#include <stdio.h>
int main() {
int num = 0x0A0B;
int mask = 0x0F << 4;
printf("%d", (num & mask) >> 4);
return 0;
}

What will be the output of the above program?

  1. A

    0

  2. B

    1

  3. C

    2

  4. D

    4

Show answer

Correct answer

  • A

    0

Question 15

+4 marksOne correct option

Consider the following C program.

c
#include <stdio.h>
#define VALUE 10
#ifdef VALUE
#undef VALUE
#define VALUE 20
#endif
int main() {
printf("%d", VALUE);
return 0;
}

What will be the output of the above program?

  1. A

    10

  2. B

    20

  3. C

    30

  4. D

    Compilation error

Show answer

Correct answer

  • B

    20

Question 16

+5 marksOne correct option

Consider the following C program.

c
#include <stdio.h>
int main(){
for(int i = 1; i<=4; i++){
for(int j = i; j<=4; j++){
if ((i*j)%3==0){
printf("%d ", i*j);
}
}
}
}

What will be the output of the above program?

  1. A

    3 6 9 12 12

  2. B

    3 6 9 12

  3. C

    3 6 12 12

  4. D

    6 9 12 12

Show answer

Correct answer

  • B

    3 6 9 12

Question 17

+5 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
void incrementNumbers(int *a, int *b) {
(*a)++;
(*b)++;
printf("a = %d, b = %d", *a, *b);
}
int main() {
int a = 5, b = 10;
incrementNumbers(&a, &b);
printf("\na = %d, b = %d", a, b);
return 0;
}

What will be the output of the above C program?

  1. A

    a = 5, b = 10
    a = 6, b = 11

  2. B

    a = 6, b = 11
    a = 6, b = 11

  3. C

    a = 5, b = 10
    a = 5, b = 10

  4. D

    a = 6, b = 11
    a = 5, b = 10

Show answer

Correct answer

  • B

    a = 6, b = 11
    a = 6, b = 11

Question 18

+5 marksOne correct option

Consider the following C program.

c
#include <stdio.h>
void swap1(int* p, int* q){
int temp = *p;
*p = *q;
*q = temp;
printf("%d %d -> ", *p, *q);
}
void swap2(int a, int b){
int temp = a;
a = b;
b = temp;
printf("%d %d -> ", a, b);
}
int main(){
int x = 5;
int y = 6;
printf("%d %d -> ", x, y);
swap1(&x, &y);
printf("%d %d -> ", x, y);
swap2(x, y);
printf("%d %d ", x, y);
}

What will be the output of the above program?

  1. A

    5 6 -> 6 5 -> 5 6 -> 5 6 -> 5 6

  2. B

    5 6 -> 6 5 -> 6 5 -> 5 6 -> 6 5

  3. C

    5 6 -> 6 5 -> 6 5 -> 5 6 -> 5 6

  4. D

    5 6 -> 6 5 -> 5 6 -> 5 6 -> 6 5

Show answer

Correct answer

  • B

    5 6 -> 6 5 -> 6 5 -> 5 6 -> 6 5

Question 19

+5 marksOne correct option

Consider the following C program.

c
#include <stdio.h>
int main(){
int arr[5] = {1,2,3,4,5};
for (int i =2; i<5;i++){
printf("%d ", *(arr+i-1) );
}
}

What will be the output of the above program?

  1. A

    1 2 3

  2. B

    0 1 2

  3. C

    5 4 3

  4. D

    2 3 4

Show answer

Correct answer

  • D

    2 3 4

Question 20

+5 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
void countCalls() {
static int count = 0;
count++;
printf("Function called %d times\n", count);
}
int main() {
countCalls();
countCalls();
countCalls();
return 0;
}

What will be the output of the above C program?

  1. A

    Function called 1 times
    Function called 1 times
    Function called 1 times

  2. B

    Function called 1 times
    Function called 2 times
    Function called 3 times

  3. C

    Function called 1 times
    Function called 1 times
    Function called 2 times

  4. D

    some_garbage_value
    some_garbage_value
    some_garbage_value

Show answer

Correct answer

  • B

    Function called 1 times
    Function called 2 times
    Function called 3 times

Question 21

+5 marksOne correct option

Consider the following C program.

c
#include <stdio.h>
int main() {
FILE* fp = fopen("output.txt", "w");
int i;
for (i = 0; i < 5; i++) {
fprintf(fp, "%d ", i);
}
fclose(fp);
fp = fopen("output.txt", "r");
int sum = 0, num;
while (fscanf(fp, "%d", &num) != EOF) {
sum += num;
}
fclose(fp);
printf("%d", sum);
return 0;
}

What will the output of the above code?

  1. A

    6

  2. B

    10

  3. C

    15

  4. D

    21

Show answer

Correct answer

  • B

    10

Question 22

+4 marksOne or more correct options

Select the correct statements from the below that dynamically allocate memory to hold a maximum of 4 integers. Assume the size of int is 4 bytes.

Select all that apply.

  1. A

    int* a = (int*)malloc(16);

  2. B

    int* a = (int*)malloc(4);

  3. C

    int* a = (int*)malloc(4*sizeof(int));

  4. D

    int* a = (int*)malloc(4*sizeof(int*));

Show answer

Correct answers

  • A

    int* a = (int*)malloc(16);

  • C

    int* a = (int*)malloc(4*sizeof(int));

Question 23

+5 marksOne or more correct options

Consider the following C program.

c
#include <stdio.h>
struct Rectangle{
int length;
int width;
};
int main(){
struct Rectangle rect = {10, 20};
struct Rectangle* rect_ptr = &rect;
// Missing statement
printf("%d", rect.length);
}

If the output of the above program is 15, then select all the options that can replace the missing statement line in the above code.

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • A
  • C

Question 24

+4 marksNumerical answer
Show answer

Correct answer: 14

Question 25

+5 marksNumerical answer

Consider the following C program.

c
#include <stdio.h>
#define SQUARE(x) (x) * (x)
#define DOUBLE(x) (2 * (x))
int main() {
printf("%d", SQUARE(DOUBLE(3)));
return 0;
}

What will be the output of the above program?

Show answer

Correct answer: 36