Hello,

please be easy with me because I have struggling learning the C language and bad english.

sizeof question:

I don't understand how to figure this without compile.

Code:
char x[4];
sizeof(x)    -> gives 4
sizeof(&x)  -> gives 8, why?
Code:
struct sockaddr_in sa;
sizeof(sa)   -> gives 16, why?
sizeof(&sa) -> gives 8, why?
Code:
unsigned long x;
sizeof(x)   -> gives 8, why?
sizeof(&x) -> gives 8, why?
how is it possible that they are same?


inet_pton: which one of them is the faster? :

my goal is given ipv4 address is valid and for that I found more than one solution using inet_pton function, I want to use the fatest solution.


Option 1:
Sending address of (unsigned long) to third parameter in inet_pton function.
Like shown here: C - IP address validation

Option 2
Sending the address of sockaddr_in to third parameter in inet_pton function.
Like shown here: Determine if a string is a valid IPv4 address in C - Stack Overflow

Option 3:
Creating an array of char (4 size), and sending it to third parameter in inet_pton function.
Beause it's doing memset 4 times: inet_pton.c source code [glibc/resolv/inet_pton.c] - Woboq Code Browser

Which one of the options is faster?

I ran benchmark using perf tool and it appears that Option 2 is the fatest as it run less time.

.