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.
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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.