C Programming Questions and Answers – Storage Management – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Storage Management – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. The function ____ obtains a block of memory dynamically.
a) calloc
b) malloc
c) both calloc & malloc
d) free
View Answer

Answer: c
Explanation: None.

2. void * malloc(size_t n) returns?
a) Pointer to n bytes of uninitialized storage
b) NULL if the request can be satisfied
c) Nothing
d) None of the mentioned
View Answer

Answer: a
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

3. calloc() returns storage that is initialized to.
a) Zero
b) Null
c) Nothing
d) One
View Answer

Answer: a
Explanation: None.

4. In function free(p), p is a _______
a) int
b) pointer returned by malloc()
c) pointer returned by calloc()
d) pointer returned by malloc() & calloc()
View Answer

Answer: d
Explanation: None.
advertisement

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char *p = calloc(100, 1);
  5.         p = "welcome";
  6.         printf("%s\n", p);
  7.     }

a) Segmentation fault
b) Garbage
c) Error
d) welcome
View Answer

Answer: d
Explanation: None.
advertisement

6. Memory allocation using malloc() is done in _________
a) Static area
b) Stack area
c) Heap area
d) Both Stack & Heap area
View Answer

Answer: c
Explanation: None.
advertisement

7. Why do we write (int *) before malloc?

int *ip = (int *)malloc(sizeof(int));

a) It is for the syntax correctness
b) It is for the type-casting
c) It is to inform malloc function about the data-type expected
d) None of the mentioned
View Answer

Answer: b
Explanation: None.

8. Which of the following is used during memory deallocation in C?
a) remove(p);
b) delete(p);
c) free(p);
d) terminate(p);
View Answer

Answer: c
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.