Question: SIMPLE PROGRAM TO TEST POINTERS Can someone explain to me why the buff in main doesn't contain the data/contents that I put inside of buff2

SIMPLE PROGRAM TO TEST POINTERS

Can someone explain to me why the buff in main doesn't contain the data/contents that I put inside of buff2

SIMPLE PROGRAM TO TEST POINTERS Can someone explain to me why the

buff in main doesn't contain the data/contents that I put inside of

#include

#include

#include

int puff(int x, char *buff2) {

char contents[7] = {'c','d','e','j','a','z'};

x = 7;

buff2 = (char *)malloc(7);

memcpy(buff2, contents, 6);

puts("buff2");

if (buff2 != NULL){

for(int i=0; i

printf("%c ",buff2[i]);

}

}

return x;

}

int main()

{

puts("Hello World");

int num = 2;

char *buff = (char *)malloc(7);

int ret =0;

ret = puff(num, buff);

puts("");

puts("buff in main");

if (buff != NULL){

for(int i=0; i

printf("%c ",buff[i]);

}

}

puts("done");

return 0;

}

#include 9 #include 10 #include 12- int puff(int x, char *buff2) 5 13 14 15 16 char contents[7] 'c','d','e','j','a', 'z'j; *malloc(7); buff2 - (char memcpy (buff2, contents, 6); puts("buff2"; if(buff2 !=NULL){ 18 19- 20 . 21 printf("%c",buff2[i]); 23 24 25 26 27 28 int main 29 I 30 return x puts("Hello World"); int num = 2; char *buff (char *)malloc(7); 32 HelloWorld buff2 c d e j a z buff in main done

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!