You are on page 1of 2

New! .

NET Interview Questions and Answers

Search

Aptitude Reasoning Verbal Ability GK Puzzles Programming Database Engineering Interview Online Test

C Programming :: Memory Allocation


@ : Home > C Programming > Memory Allocation > Find Output of Program

Exercise

6.

Assume integer is 2 bytes wide. What will be the output of the following code?

General Questions Find Output of Program Point Out Errors Point Out Correct Statements True / False Questions Yes / No Questions

#include<stdio.h> #include<stdlib.h> #define MAXROW 3 #define MAXCOL 4


int main() { int (*p)[MAXCOL]; p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p)); printf("%d, %d\n", sizeof(p), sizeof(*p)); return 0; } A. C. 2, 8 8, 24 B. D. 4, 16 16, 32

"Life is like riding a bicycle. To keep your balance you must keep moving." - Albert Einstein

Answer & Explanation

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.

View Answer Online Compiler Report Discuss in Forum

7.

How many bytes of memory will the following code reserve?

#include<stdio.h> #include<stdlib.h>
int main() { int *p; p = (int *)malloc(256 * 256); if(p == NULL) printf("Allocation failed"); return 0; } A. C. 65536 Error B. D. Allocation failed No output

Answer & Explanation

Answer: Option B

Explanation: Hence 256*256 = 65536 is passed to malloc() function which can allocate upto 65535. So the memory allocation will be failed in 16 bit platform (Turbo C in DOS).

If you compile the same program in 32 bit platform like Linux (GCC Compiler) it may allocate the required memory.

View Answer Online Compiler Report Discuss in Forum

< Prev 12

Read more:

Memory Allocation - Point Out Errors Memory Allocation - Point Out Correct Statements Memory Allocation - True / False Questions Memory Allocation - Yes / No Questions

2008-2011 by IndiaBIX Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy Advertise Contact us: info@indiabix.com Follow us on twitter!

Bookmark to:

You might also like