I have this function:
void print_pol(char* pol); //or char[]
printf("%s", pol);
}
In main(), I call this function as below
print_pol("pol1");
But I didn't allocate memory for char* pol in the program. So how is this possible? I know that a pointer must point to something.
"poll1"is a string literal with type length-6 array of char,char[6]. The data itself is stored in read-only memory. Your function parameterpolmay look like an array, but it is adjusted tochar*, giving you this:When you pass it the literal to the function, it decays into a pointer to its first element. No allocation is required on your side.