hello,
i know its a basic question on pointers/malloc , but i wud still like if u can explain y in the following code we need to allocate memory to str2 and str3 be4 using strcpy and memcpy??
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char str1[]="This is for testing";
char *str2;
char *str3;
strcpy(str2,str1); //Copies the contents of str1 to str2
memcpy(str3,str1,strlen(str1)); //Copies the contents of str1 to str3
printf("String 2 using strcpy(): %s\nString 3 using memcpy(): %s\n",str2,str3);
}