How to get char array size in this case?

arrays, c, char, sizeof

Solution

`sizeof(x)` in your code will return the size of pointer `char *x` and not the size of the char array that `x` is pointing on

and the size of pointer in your 64-bits system is 8. and for 32-bits system the size of pointer is 4

Problem

I'm with this doubt: how to get the size of a char array in this case: ``` #include<stdio.h> void f(char * x) { printf("Size %d\n", sizeof(x)/sizeof(char)); } main() { char x[5] = {'a', 'e', 'i', 'o', 'u'}; f(&x[0]); } ``` Contrary to my expectations, I'm receiving 8 rather than 5 or even 6. What is wrong here? Thanks!

Original source

Related problems