Return values at function argument pointers
Pointers Sample application:
----------------------------------------
int Function( char* arr)
{
strcpy(arr,"sun");
return 0;
}
void Main()
{
char arr[3];
Function(arr);
printf("\n %s",arr);
}
Expected Output : sun
Actual Result : I got some invalid junk data;
So I modified the main()fn call as follows:
void Main()
{
char arr[3];
Function(&arr[0]);
printf("\n %s",arr);
}
the Output is : sun
----------------------------------------
int Function( char* arr)
{
strcpy(arr,"sun");
return 0;
}
void Main()
{
char arr[3];
Function(arr);
printf("\n %s",arr);
}
Expected Output : sun
Actual Result : I got some invalid junk data;
So I modified the main()fn call as follows:
void Main()
{
char arr[3];
Function(&arr[0]);
printf("\n %s",arr);
}
the Output is : sun
Labels: Pointers
0 Comments:
Post a Comment
<< Home