Quiz Space

September 2023 term · Introduction to C Programming · CS1101

Intro to C Programming End Term: 24 December 2023, Set AEF3 (September 2023 term)

The IIT Madras BS Introduction to C Programming (Intro to C Programming) End Term paper sat on 24 Dec 2023, in the September 2023 term, set AEF3: 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
MCQ
17
MSQ
6
Numerical
2

Updated

Official paper: IIT M ES FOUNDATION FN EXAM FEF1 24 Dec 2023 · No negative marking.

Question 1

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
int a = 10;
int main()
{
int a = 30;
{
printf("Value of a is %d", a);
}
printf("\nValue of a is %d", a);
return 0;
}

Which of the following is the correct output for the above program?

  1. A

    Value of a is 30
    Value of a is 30

  2. B

    Value of a is 30
    Value of a is 10

  3. C

    Value of a is 10
    Value of a is 10

  4. D

    Value of a is 10
    Value of a is 30

Show answer

Correct answer

  • A

    Value of a is 30
    Value of a is 30

Question 2

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
int main()
{
int a = 3;
switch(a++)
{
case 1: a = a + 20;
case 2: a = a - 3;
case 3: a = a * 4;
case 4: a = a / 2;
default: a = a * a;
}
printf("%d", a);
}

What will be the output of the above C program?

  1. A

    12

  2. B

    2

  3. C

    16

  4. D

    1

  5. E

    64

Show answer

Correct answer

  • E

    64

Question 3

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
void compute (int a, int b)
{
a = a + 5;
b = b - 2;
}
int main()
{
int a = 234, b = 316;
compute(a, b);
printf("%d %d", a, b);
return 0;
}

What will be the output of the above C program?

  1. A

    Compile Time Error

  2. B

    239 314

  3. C

    234 316

  4. D

    239 316

  5. E

    234 314

Show answer

Correct answer

  • C

    234 316

Question 4

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
int s(int n)
{
if (n == 1){
return n;
}
n += s(n-1);
return n;
}
int main()
{
int n= 6;
printf("%d", s(n));
return 0;
}

How many times function s() will be called in the above program, including the first call from the main function?.

  1. A

    3

  2. B

    4

  3. C

    5

  4. D

    6

Show answer

Correct answer

  • D

    6

Question 5

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
void fun(int *x)
{
*x = *x * 2;
}
int main() {
int num = 4;
fun(&num);
printf("The value is: %d", num);
return 0;
}

What is the output of the above C program?

  1. A

    The value is: 4

  2. B

    The value is: 8

  3. C

    The value is: 16

  4. D

    The value is: 2

Show answer

Correct answer

  • B

    The value is: 8

Question 6

+4 marksOne correct option

Consider an integer variable holding a value “0x89209899”. Suppose the available memory addresses are starting from the address “0x128” in a machine, which of the following stores this multibyte data in the little endian way?

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

Correct answer

  • C

Question 7

+4 marksOne correct option

Which of the following statements about array initialization in C is correct?

  1. A

    Arrays can only be initialized at the time of declaration.

  2. B

    Arrays can be initialized both at the time of declaration and later in the program.

  3. C

    Arrays can only be initialized with integer values.

  4. D

    The index of the first element in an array is always 1.

Show answer

Correct answer

  • B

    Arrays can be initialized both at the time of declaration and later in the program.

Question 8

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
int main()
{
char *s = "Hello C Programming !!";
char *p = s + 6;
printf("%s", p);
return 0;
}

What will be the output of the above C program?

  1. A

    Hello C Programming !!

  2. B

    Hello C Programming

  3. C

    C Programming

  4. D

    C Programming !!

  5. E

    Programming

  6. F

    Programming !!

Show answer

Correct answer

  • D

    C Programming !!

Question 9

+4 marksOne correct option

Consider the C program given below.

c
#include <stdio.h>
struct Score
{
int rollNo;
int marks;
};
void print_score(struct Score p)
{
/// Missing code
}
int main()
{
struct Score S1= {10001,80};
print_score(S1);
return 0;
}

select all the correct implementations of function print_score if the output of the above program is 10001 80.

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

Correct answer

  • A

Question 10

+4 marksOne correct option

Consider the below C program.

c
#include <stdio.h>
enum Level {
A,
B = 7,
C
};
int main()
{
enum Level var = A;
printf("%d", var);
return 0;
}

What will be the output of the above program?

  1. A

    0

  2. B

    6

  3. C

    7

  4. D

    1

Show answer

Correct answer

  • A

    0

Question 11

+4 marksOne correct option

Which of the following statements is true about unions in C?

  1. A

    Unions allow you to store values of different data types at a time in different members.

  2. B

    Unions can only contain elements of the same data type.

  3. C

    Unions always consume more memory than structs.

  4. D

    Unions are used to define functions.

Show answer

Correct answer

  • A

    Unions allow you to store values of different data types at a time in different members.

Question 12

+4 marksOne correct option

Consider the C program given below.

c
#include <stdio.h>
typedef
{
int* a;
int len;
} Array;
int main(){
Array a = {(int *)malloc(sizeof(int)*5), 5};
return 0;
}

If the size of int is 4 and the system uses 32-bit architecture, what are the amount of spaces allocated in the stack and in the heap respectively?

  1. A

    4, 20

  2. B

    4, 40

  3. C

    8, 20

  4. D

    8, 40

Show answer

Correct answer

  • C

    8, 20

Question 13

+4 marksOne correct option
  1. A

    *(*A + i*R + j)

  2. B

    *(*A + j*C + i)

  3. C

    *(*A + i*C + j)

  4. D

    *(*A + j*R + i)

Show answer

Correct answer

  • C

    *(*A + i*C + j)

Question 14

+4 marksOne correct option

Consider the following code.

c
#include <stdio.h>
int main() {
FILE *file = fopen("numbers.txt", "a");
fprintf(file, "%d %d %d", 1, 2, 3);
fclose(file);
return 0;
}

What does this C program do?

  1. A

    Remove all data from file and write "1,2,3" to "numbers.txt".

  2. B

    Remove all data from file and write "1 2 3" to "numbers.txt".

  3. C

    Appends "1,2,3" to "numbers.txt".

  4. D

    Appends "1 2 3" to "numbers.txt".

Show answer

Correct answer

  • D

    Appends "1 2 3" to "numbers.txt".

Question 15

+4 marksOne correct option

Consider the C program given below.

c
#include <stdio.h>
int main() {
unsigned int mask = 0x04;
unsigned int x = 0xDBA5;
for(int i=0;i<4;i++){
x &= ~mask;
mask<<=4;
}
printf("%X",x);
}

What will be the output of the above program?

  1. A

    9BB1

  2. B

    9BA1

  3. C

    BBA1

  4. D

    BBB1

Show answer

Correct answer

  • B

    9BA1

Question 16

+4 marksOne correct option

Consider the following C code.

c
#include <stdio.h>
#define ABC(a, b) a ## b
int main()
{
int value = ABC(3, 4);
printf("%d", value);
return 0;
}

What will be the output of the given code?

  1. A

    34

  2. B

    7

  3. C

    12

  4. D

    Compilation error

Show answer

Correct answer

  • A

    34

Question 17

+4 marksOne correct option

Which of the following preprocessor directives is used to define macros in C?

  1. A

    define

  2. B

    include

  3. C

    ifdef

  4. D

    undef

Show answer

Correct answer

  • A

    define

Question 18

+4 marksOne or more correct options

Which of the following statements is/are true regarding functions in C Language?

Select all that apply.

  1. A

    A function signature must indicate the data type of all the function parameters.

  2. B

    A function signature must indicate the variable names for the function parameters.

  3. C

    A function does not always return a value.

  4. D

    A function cannot accept more than 2 parameters.

Show answer

Correct answers

  • A

    A function signature must indicate the data type of all the function parameters.

  • C

    A function does not always return a value.

Question 19

+4 marksOne or more correct options

In C, which of the following is/are valid operations on pointer variables? (Select all that apply)

Select all that apply.

  1. A

    Dividing one pointer variable by another pointer variable.

  2. B

    Comparing two pointers variables for equality.

  3. C

    Incrementing/Decrementing a pointer variable (e.g. ptr++/ ptr–).

  4. D

    Multiplying two pointer variables.

Show answer

Correct answers

  • B

    Comparing two pointers variables for equality.

  • C

    Incrementing/Decrementing a pointer variable (e.g. ptr++/ ptr–).

Question 20

+4 marksOne or more correct options

Consider the below C program.

c
#include <stdio.h>
int main()
{
int a = 10;
int *p = &a;
printf("%d", ??);
return 0;
}

Which of the following options can replace the “??” in the above code so that the output of the program becomes 10?

Select all that apply.

  1. A

    *a

  2. B

    &a

  3. C

    a

  4. D

    p

  5. E

    *p

  6. F

    &p

Show answer

Correct answers

  • C

    a

  • E

    *p

Question 21

+4 marksOne or more correct options

Select all that apply.

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

Correct answers

  • B
  • D

Question 22

+4 marksOne or more correct options

Consider the below C program.

c
#include<stdio.h>
int main()
{
typedef int Number;
?? marks = 20;
printf("%d", marks);
}

Which of the following can be used in place of “??” in the above code to print 20 in output?

Select all that apply.

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

Correct answers

  • A
  • C

Question 23

+4 marksOne or more correct options

Consider the below C function.

c
int** twoDimArray(int row, int col)
{
int i, j;
int **arr = (int**) malloc(row * sizeof(int *));
for (int i = 0; i < row; i++){
arr[i] = (int*) calloc(col, sizeof(int));
}
return arr;
}

Which of the following statements is true wrt the above function?

Select all that apply.

  1. A

    The function allocates the memory for a 2D array at the time of compilation.

  2. B

    The function dynamically allocates the memory for a 2D array.

  3. C

    The function does not initialize the elements of the 2D array.

  4. D

    The function initializes all the elements of the 2D array with 0.

Show answer

Correct answers

  • B

    The function dynamically allocates the memory for a 2D array.

  • D

    The function initializes all the elements of the 2D array with 0.

Question 24

+4 marksNumerical answer

Consider the following code.

c
#include <stdio.h>
int main()
{
int arr[8];
arr[0] = 0;
arr[1] = 1;
for (int i = 2; i < 8; i++)
{
arr[i] = arr[i-1] + arr[i-2];
}
printf("%d", arr[6]);
return 0;
}

What will be the output of this C program?

Note: The answer input must be an integer. For Ex: If the answer is 32, you must enter 32 only.

Show answer

Correct answer: 8

Question 25

+4 marksNumerical answer

Consider the below C program.

c
#include <stdio.h>
void demo()
{
static int x = 2;
x++;
}
int main()
{
demo();
demo();
demo();
demo();
return 0;
}

What will be the value of the static variable “x” just before the execution of the return statement in the main function?

Note: The answer must be an integer. For Ex: If the answer is 32, you must enter 32 only.

Show answer

Correct answer: 6