21. What will be the output of following code :
// Assume all header files are included
main()
{
int *ptr;
ptr=malloc(sizeof(int));
*ptr=200;
printf("The value of allocated object is %d",*ptr);
}
A. The value of allocated object is 200
B. 200
C. Compilation Error
D. None of these
View Answer & Explanation
Ans. C
malloc() function returns void type address of the allocated memory. Hence before assigning this address to specific pointer type casting is required.
22. What will be the output of following code :
// Assume all header files are included
main()
{
int *ptr;
ptr=(int*)malloc(sizeof(int));
*ptr=200;
printf("The value of allocated object is %d",*ptr);
}
A. The value of allocated object is 200
B. 200
C. Compilation Error
D. None of these
View Answer & Explanation
Ans. A