Explore topic-wise MCQs in C Programming.

This section includes 13 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 if size is zero in the following C statement?
realloc(ptr, size)

A. Doesn t do any reallocation of ptr i.e. no operation
B. Undefined behaviour
C. Allocate a memory location with zero length
D. Free the memory pointed to by ptr
E. None of these
Answer» E. None of these
2.

What will be the output of the program:-
extern int i = 5;
main()
(
int i=7;
printf("%d",i);
}

A. 5
B. compiler error
C. 7
D. garbage value
Answer» D. garbage value
3.

Why do we write (int *) before malloc?
int *ip = (int *)malloc(sizeof(int));

A. It is to inform malloc function about the data-type expected
B. It is for the syntax correctness
C. It is for the type-casting
D. All of above
E. None of these
Answer» D. All of above
4.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *ptr = calloc(200, 2);
ptr = "Interview Mania";
printf("%s n", ptr);
}

A. Interview Mania
B. Compilation Error
C. Garbage
D. Segmentation fault
E. None of these
Answer» B. Compilation Error
5.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
struct p *next;
int n;
};
int main()
{
struct p* ptr1 = malloc(sizeof(struct p));
ptr1->n = 1;
ptr1->next = malloc(sizeof(struct p));
printf("%d n", ptr1->next->n);
return 0;
}

A. Garbage value
B. 1
C. 0
D. Compilation error
E. None of these
Answer» B. 1
6.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
struct p *next;
int n;
};
int main()
{
struct p *ptr1 = calloc(1, sizeof(struct p));
ptr1->n = 1;
ptr1->next = calloc(1, sizeof(struct p));
printf("%d n", ptr1->next->n);
return 0;
}

A. 0
B. 1
C. Somegarbage value
D. Compilation Error
E. None of these
Answer» B. 1
7.

Which of the following should be used for freeing the memory allocated in the following C code?
#include <stdio.h>
struct p
{
struct p *next;
int n;
};
int main()
{
struct p *ptr1 = (struct ptr*)malloc(sizeof(struct p));
ptr1->n = 1;
ptr1->next = (struct ptr*)malloc(sizeof(struct p));
return 0;
}

A. free(ptr1);
B. All of above
C. None of these
Answer» D.
8.

What if size is zero in the following C statement?

A. Doesn t do any reallocation of ptr i.e. no operation
B. Undefined behaviour
C. Allocate a memory location with zero length
D. Free the memory pointed to by ptr
E. None of these
Answer» E. None of these
9.

Where are the uninitialized global variables stored?

A. stack segment
B. heap segment
C. text segment
D. BSS
Answer» E.
10.

What will be the output of the program:- extern int i = 5; main() ( int i=7; printf("%d",i); }

A. 5
B. compiler error
C. 7
D. garbage value
Answer» D. garbage value
11.

Which of the following should be used for freeing the memory allocated in the following C code?

A. free(ptr1);
B. <pre class="prettyprint lang-c">free(ptr1);<br> free(ptr1-&gt;next)<br></pre>
C. <pre class="prettyprint lang-c">free(ptr1-&gt;next);<br> free(ptr1);<br></pre>
D. All of above
E. None of these
Answer» D. All of above
12.

Why do we write (int *) before malloc?

A. It is to inform malloc function about the data-type expected
B. It is for the syntax correctness
C. It is for the type-casting
D. All of above
E. None of these
Answer» D. All of above
13.

In function free(p), p is a _______.

A. Pointer returned by malloc() & calloc()
B. Pointer returned by calloc()
C. Pointer returned by malloc()
D. int
E. None of these
Answer» B. Pointer returned by calloc()