Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions