I'm currently learning C and I am struggling on the concept of pointers. I want to calculate the size of a char array within the respective function to limit the amount of parameters needed:
char palindrome(const char str[], int count);
int main() {
char input[] = "anna";
int size = sizeof(input) / sizeof(input[0]); // size = 5
palindrome(input, size);
return EXIT_SUCCESS;
}
char palindrome(const char str[], int count) {
int size = sizeof(str) / sizeof(str[0]); // size = 1?
code...
return EXIT_SUCCESS;
}
If anyone can explain why the value of size differs I would really appreciate it as I think the way I use '&' and '*' is partly incorrect. for example a pointer would refer to the address of where the variable is stored (i.e. any variable change using asterisks would globally change x's value?). I don't understand the difference of declaring a variable compared to a pointer I think is the issue.
Many thanks, Callum