Question: 1. This program will allocate the memory of ---- bytes for pointer ptr (Assuming that integers occupy 4 byte) and explain why the output is
1. This program will allocate the memory of ---- bytes for pointer "ptr" (Assuming that integers occupy 4 byte) and explain why the output is so?
#include#include
int main() {
int *ptr; ptr = (int*) malloc(sizeof(int)*3); ptr = realloc(ptr,sizeof(int)*2); return 0;
}
2. What is the output of the following program and why explain?
#include#include
int main() {
int *ptr; ptr = (int *) calloc(1,sizeof(int)); if (ptr != 0)
printf("%d ",*ptr); return 0; }
3. What is the output of the following program and explain why?
#include#include
int main() {
int *ptr; ptr = (int *) malloc(sizeof(int)); if (ptr != 0)
printf("%d ",*ptr); return 0; }
4. Can we increase the size of dynamically allocated array (to 40)? If yes, increase the size of P in the following program? Explain why?
#include#include
int main() {
int *p; p = (int*) malloc(20);
// WRITE YOUR CODE HERE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
