Explore topic-wise MCQs in C Programming.

This section includes 202 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What will be the output of the program assuming that the array begins at location 1002?

A. 1002, 2004, 4008, 2
B. 2004, 4008, 8016, 1
C. 1002, 1002, 1002, 1
D. Error
Answer» D. Error
2.

Which statement will you add to the following program to ensure that the program outputs "IndiaBIX" on execution?

A. *pt='';
B. pt='\0';
C. pt='\n';
D. *pt='\0';
Answer» E.
3.

In the following program add a statement in the function such that the factorial gets stored in .

A. j=s;
B. *j=s;
C. *j=&s;
D. &j=s;
Answer» C. *j=&s;
4.

Are the expression and are same?

A. True
B. False
Answer» C.
5.

Which of the following statements correct about used in the below statement?

A. is a pointer to a pointer to a pointer to a char
B. is a pointer to a pointer to a pointer to a pointer to a char
C. is a pointer to a char pointer
D. is a pointer to a pointer to a char
Answer» C. is a pointer to a char pointer
6.

In the following program add a statement in the function such that address of gets stored in ?

A. **k=a;
B. k=&a;
C. *k=&a
D. &k=*a
Answer» D. &k=*a
7.

Point out the compile time error in the program given below.

A. Error: invalid assignment for x
B. Error: suspicious pointer conversion
C. No error
D. None of above
Answer» D. None of above
8.

Will the program compile?

A. True
B. False
Answer» B. False
9.

The following program reports an error on compilation.

A. True
B. False
Answer» C.
10.

Are the three declarations and same?

A. True
B. False
Answer» C.
11.

Is there any difference between the following two statements?

A. Yes
B. No
Answer» C.
12.

Is this a correct way for NULL pointer assignment?

A. Yes
B. No
Answer» C.
13.

Will the program compile in Turbo C?

A. Yes
B. No
Answer» C.
14.

Will the following program give any warning on compilation in TurboC (under DOS)?

A. Yes
B. No
Answer» C.
15.

Can you combine the following two statements into one?

A. char p = *malloc(100);
B. char *p = (char) malloc(100);
C. char *p = (char*)malloc(100);
D. char *p = (char *)(malloc*)(100);
Answer» D. char *p = (char *)(malloc*)(100);
16.

What would be the equivalent pointer expression for referring the array element

A. ((((a+i)+j)+k)+l)
B. *(*(*(*(a+i)+j)+k)+l)
C. (((a+i)+j)+k+l)
D. ((a+i)+j+k+l)
Answer» C. (((a+i)+j)+k+l)
17.

How many bytes are occupied by and pointers (DOS)?

A. near=2 far=4 huge=4
B. near=4 far=8 huge=8
C. near=2 far=4 huge=8
D. near=4 far=4 huge=8
Answer» B. near=4 far=8 huge=8
18.

What is the output of this C code?
#include <stdio.h>
int main()
{
char *p[1] = {"Interview Mania"};
printf("%s", (p)[0]);
return 0;
}

A. Compile time error
B. Undefined behavior
C. Interview Mania
D. None of the mentioned
Answer» D. None of the mentioned
19.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
int *ptr1 = (int *)4;
int *ptr2 = (int *)6;
printf("%d", ptr1 + ptr2);
}

A. 4
B. 6
C. Compilation Error
D. Garbage value
E. 10
Answer» D. Garbage value
20.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
double *p = (double *)150;
p = p + 5;
printf("%u", p);
}

A. 150
B. 160
C. 170
D. 180
E. 190
Answer» F.
21.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *str = "PRAYAG";
char *ptr = str;
printf("%c %c", *ptr, str[2]);
}

A. P A
B. PRAYAG P
C. Garbage value
D. Compilation Error
E. None of these
Answer» B. PRAYAG P
22.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *str = "AJIT";
char *ptr = str;
printf("%c %c", *(ptr + 2), str[2]);
}

A. Ajit
B. A A
C. Compilation Error
D. I I
E. None of these
Answer» E. None of these
23.

Which of following logical operation can be applied to pointers?
(Assuming initialization int *p = 12; int *q = 13;)

A. p ^ q
B. p & q
C. p | q
D. All of above
E. None of these
Answer» F.
24.

Which of the following arithmetic operation can be applied to pointers p and q?
(Assuming initialization as int *p = (int *)6; int *q = (int *)7;)

A. p / q
B. p + q
C. p q
D. p * q
E. None of these
Answer» D. p * q
25.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
void *ptr1;
int var[5] = {50, 60, 70, 80, 90};
ptr1 = &var[3];
int *ptr2 = &var[4];
int m = (int*)ptr1 - ptr2;
printf("%d n", m);
}

A. 90
B. Compilation Error
C. Garbage value
D. -1
E. None of these
Answer» E. None of these
26.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
void *ptr1;
int num[5] = {10, 20, 30, 40, 80};
ptr1 = &num[4];
int *ptr2 = &num[3];
int R = ptr1 - ptr2;
printf("%d n", R);
}

A. 80
B. 40
C. 30
D. 20
E. Compilation Error
Answer» B. 40
27.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
int arr[5] = {61, 62, 63, 64, 65};
void *p = &arr[1];
void *p1 = &arr[5];
int Res = 0;
Res = p1 - p;
printf("%d n", Res);
}

A. Compilation Error
B. Depends on the compiler
C. 16
D. Garbage value
E. None of these
Answer» D. Garbage value
28.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
int array[3] = {16, 17, 18};
int *p = &array[1];
float m = 1;
p = p + m;
printf("%d n", *p);
}

A. 16
B. 17
C. 18
D. Compilation Error
E. Garbage value
Answer» E. Garbage value
29.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
int num[5] = {15, 25, 35, 45, 55};
int *ptr1 = &num[3];
int *ptr2 = &num[4];
ptr2 = ptr2 * 1;
printf("%d n", *ptr2);
}

A. Garbage value
B. Compilation Error
C. Runtime Error
D. Undefined behaviour
E. None of these
Answer» C. Runtime Error
30.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *s = "Interview Mania";
char strArray[] = "Interview Mania";
printf("%d %d n", sizeof(s), sizeof(strArray));
return 0;
}

A. 8 16
B. Compilation Error
C. Interview Mania
D. 16 8
E. None of these
Answer» E. None of these
31.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
int array1[5] = {10, 20, 30, 40, 50};
int array2[5] = {11, 21, 31, 41, 51};
int R = &array2[3] - &array1[2];
printf("%d n", R);
}

A. -7
B. Compilation Error
C. Garbage value
D. 50
E. None of these
Answer» B. Compilation Error
32.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char s[] = "Interveiw Mania";
s[9] = '.';
printf("%s n", s);
return 0;
}

A. Interveiw Mania
B. Compilation Error
C. Interveiw.Mania
D. Segmentation fault
E. None of these
Answer» D. Segmentation fault
33.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *ch = "Interview Mania n";
ch[9] = '.';
printf("%s n", ch);
return 0;
}

A. Segmentation fault
B. Compilation Error
C. Interview Mania
D. Undefined behaviour
E. None of these
Answer» B. Compilation Error
34.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *s1 = "Interview Mania ";
char s2[] = "welcome to n";
strcpy(s2, s1);
printf("%s n", s2);
return 0;
}

A. Welcome to
B. Interview Mania
C. Welcome to Interview Mania
D. All of above
E. None of these
Answer» C. Welcome to Interview Mania
35.

Comment on the output of the following C code.
#include <stdio.h>
int main()
{
char *s = "Interveiw" //Line 1
char *p = "Mania n"; //Line 2
s = p; //Line 3
printf("%s, %s n", s, p); //Line 4
}

A. Output will be Interveiw, Mania
B. You cannot assign pointer like in Line 3
C. Memory holding this is cleared at line 3
D. Memory holding this loses its reference at line 3
E. None of these
Answer» E. None of these
36.

What will be the output of the following C code?
#include <stdio.h>
void function(char *p)
{
printf("%s", p);
}
void main()
{
char str[] = "Interveiw Mania";
function(str);
}

A. Nothing
B. Undefined behaviour
C. Interveiw Mania
D. Compilation Error
E. None of these
Answer» D. Compilation Error
37.

What will be the output of the following C code?
#include <stdio.h>
void fun(char *p)
{
p++;
p[3] = 'N';
printf("%c n", *p);
}
void main()
{
char s[] = "WELCOME";
fun(s);
}

A. WELCOME
B. N
C. E
D. Garbage value
E. None of these
Answer» D. Garbage value
38.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *String = "Interveiw Mania";
char StringArray[] = "Interveiw Mania";
printf("%d %d n", strlen(String), strlen(StringArray));
return 0;
}

A. Interveiw Mania
B. 15 15
C. 15
D. Compilation Error
E. Garbage value
Answer» C. 15
39.

What will be the output of the following C code?
 #include <stdio.h>
void count(char *ptr)
{
ptr++;
ptr[3] = 'S';
}
void main()
{
char str[] = "AJIT";
count(str);
printf("%c n", *str);
}

A. A
B. AJIT
C. Compilation Error
D. Garbage value
E. None of these
Answer» B. AJIT
40.

What is the correct way to declare and assign a function pointer?
(Assuming the function to be assigned is "int multi(int, int);")

A. int *fn_ptr(int, int) = multi;
B. int *fn_ptr(int, int) = &multi;
C. int (*fn_ptr)(int, int) = multi;
D. All of above
E. None of these
Answer» D. All of above
41.

What will be the output of the following C code?
#include <stdio.h>
int calc(int n, int m)
{
return n + m;
}
int main()
{
int (*calc_ptr)(int, int);
calc_ptr = calc;
printf("The Addition of two numbers is: %d", (int)calc_ptr(21, 13));
}

A. 21
B. 13
C. Compilation Error
D. 34
E. None of these
Answer» E. None of these
42.

What substitution should be made to //-Reference such that p1 points to variable t3 in the following C code?
#include <stdio.h>
int main()
{
int t1 = 1, t2 = 2, t3 = 3;
int *p1 = &t1;
int **p2 = &p1;
//-Reference
}

A. **p2 = &t3;
B. *p1 = &t3;
C. *p2 = &t3;
D. All of above
E. None of these
Answer» D. All of above
43.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
int n[5] = {10, 20, 30, 40, 50};
int *p1 = n;
int **p2 = &p1;
printf("%p %p", *p1, n);
}

A. Same memory address is printed
B. 10, 20
C. 40, 50
D. Different memory address is printed
E. None of these
Answer» E. None of these
44.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
int p = 1, q = 2, r = 3;
int *p1 = &p, *p2 = &q, *p3 = &r;
int **p4 = &p1; //-Reference
*p4 = p2;
}

A. p4 points to p2
B. p1 points to p
C. p1 points to q
D. All of above
E. None of these
Answer» B. p1 points to p
45.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
int var[4] = {11, 21, 31, 41};
int *ptr1 = var;
int **ptr2 = &ptr1;
printf("%p %p", *ptr2, var);
}

A. Same memory address is printed.
B. Different memory address is printed.
C. 11, 21, 31, 41
D. 41, 31
E. None of these
Answer» B. Different memory address is printed.
46.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
int t = 12;
int *q1 = &t;
int **q2 = &q1;
**q2 = 13;
printf("%d n", t);
}

A. Compilation Error
B. 12
C. 13
D. Garbage value
E. None of these
Answer» D. Garbage value
47.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
int m = 10;
int *ptr1 = &m;
int **ptr2 = &ptr1;
printf("%d %d %d n", m, *ptr1, **m);
}

A. 10, 10, 10
B. Same memory address
C. Different memory address
D. Garbage value
E. Compilation Error
Answer» F.
48.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
int var = 151;
int *p1 = &var;
int **p2 = &p1;
printf("%d, %d, %d n", var, *p1, **p2);
}

A. Garbage value, 151, 151
B. 151, 151, Garbage value
C. Compilation Error
D. 151, 151, 151
E. None of these
Answer» E. None of these
49.

Comment on the output of the following C code.
 #include <stdio.h>
int main()
{
int n = 151;
int **ptr -= &&n;
}

A. Garbage value
B. Compilation Error
C. 151
D. You cannot apply any arithmetic operand to a pointer
E. We don t have address of an address operator
Answer» F.
50.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *ch[20] = {"Welcome", "to", "Interview mania"};
int n = 0;
for (n = 0; n < 20; n++)
printf("%s", *(ch[n]));
}

A. Welcome to Interview mania
B. Compilation Error
C. Garbage value
D. Segmentation fault
E. None of these
Answer» E. None of these