MCQ on Memory allocation and compilation process
1. What will be the output of the following code?
(a) Garbage value
(c) Syntax Error
Unions provide an efficient way of using the same memory location. All member of Union uses same memory location which has maximum space.
Here, float f is used which has
f = 20.60f = 20.600000
. So, option (b) is correct.
2. Which is the correct sequence of compilation process?
(a) Assembler → Compiler → Preprocessor → Linking
(b) Compiler → Assembler → Preprocessor → Linking
(c) Preprocessor → Compiler → Assembler → Linking
(d) Assembler → Compiler → Linking → Preprocessor
Option (c) is correct.
3. During preprocessing, the code #include gets replaced by the contents of the file stdio.h. Which is true?
(a) During linking the code #include replaces by stdio.h
(c) During execution the code #include replaces by stdio.h
(d) During editing the code #include replaces by stdio.h
Preprocessing enlarges and boosts the C programming language by replacing preprocessing directive #include with the content of the file stdio.h.
4. Why to use fflush() library function?
(a) To flush all streams and specified streams
(b) To flush only specified stream
(c) To flush input/output buffer
(d) Invalid library function
As defined Use of fflush(stdin) in C : fflush() is typically used for output stream only. Its purpose is to clear (or flush) the output buffer and move the buffered data to console (in case of stdout) or disk (in case of file output stream).
Option (a) is correct.
5. Point out the error ->
(a) Error: in strcpy() statement.
(b) Error: in *ptr = (int *) malloc(30);
(c) Error: in free(ptr);
(d) No error
Assignment makes integer from pointer without a cast. Option (b) is true.
6. Why is calloc() function used for?
(a) allocates the specified number of bytes
(b) allocates the specified number of bytes and initializes them to zero
(c) increases or decreases the size of the specified block of memory and reallocates it if needed
(d) calls the specified block of memory for execution.
- malloc() : allocates the specified number of bytes.
- realloc() : increases or decrease the size of the specified block of memory. Reallocates it if needed.
- calloc() : allocates the specified number of bytes and initializes them to zero.
- free() : releases the specified block of memory back to the system.
So, option (b) is correct.
This article is contributed by Nikita Tiwari. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Please Login to comment...