0 votes
in Education by (1.7m points)
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?

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
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.
...