So my professor gave me (where x is a C executable):
$ ./x y z w
He said the memory size of argv in int main(int argc, char **argv) is 48 bytes, including itself.
Can someone help explain this to me?
argv is, as the function says, a pointer to a pointer to a char, which in terms of size means it's a pointer. Generally (almost always but not guaranteed?), all pointers are the same size. If this is a 64-bit machine, pointers will be 8 bytes in size. In this case, argv contains five elements: pointers to five char pointers: './x', 'y', 'z', 'w', and NULL, since argv is NULL-terminated.
By my calculations, that leaves 40 bytes in argv, so I'm not sure where he's getting the other 8.
Edit: As someone else suggested, argv itself would also take up room for a pointer, so there's the other 8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With