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


#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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
