In the below pusedo code, the function display has char* as input parameter and a string "apple" is passed. In the function the elements of the string are accessed by index. Here there is no memory for the string "apple" then how this is getting accessed in the display function
#include <stdio.h>
void display(char * str)
{
int i = 0;
while ('\0' != str[i])
{
printf("%c", str[i]);
i++;
}
}
int main()
{
display("apple");
return 0;
}
The function works correctly and gives output as apple. This approach is seen in many programs but I would like to know where the memory will be assigned to the string "apple". And also what are the potential problems in this usage.