Why is there no error when the return value is not catched?
#include <iostream>
#include <stdlib.h>
#include<assert.h>
char* StringCopy(char* string) //Returns a pointer to the heap memory
location which stores the duplicate string
{
long length=strlen(string) +1;
char *newString;
newString=(char*)malloc(sizeof(char)*length);
assert(newString!=NULL);
strcpy(newString,string);
return(newString);
}
int main(int argc, const char * argv[])
{
char name[30]="Kunal Shrivastava";
StringCopy(name);//There is no error even when there is no pointer
which stores the returned pointer value from the
function StringCopy
return 0;
}
As far as I know, the value received from a return type function must be
stored where it is called or else it is erroneous.
Please explain to me how is this working fine.
I am using c++ in Xcode.
Thank you.
No comments:
Post a Comment