Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

Question regarding memory allocation in C

I am having a difficult time getting why the answer is 66 bytes to the following question:

How much memory gets allocated for the data passed through the pointer in the main functions 2nd parameter(not considering the pointer size) in a 64 bit system, if the app is run with

./program alfa beta gamma
question from:https://stackoverflow.com/questions/65643432/question-regarding-memory-allocation-in-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The best I could come up with is

argv[0] ==> 8 bytes for pointer itself + 6 bytes for the data ("./app") ==> 14
argv[1] ==> 8 bytes for pointer itself + 5 bytes for the data ("alfa") ==> 13
argv[2] ==> 8 bytes for pointer itself + 5 bytes for the data ("beta") ==> 13
argv[3] ==> 8 bytes for pointer itself + 6 bytes for the data ("gamma") ==> 14
argv[4] ==> 8 bytes for the pointer (NULL) ==> 8

TOTAL: 62

Maybe add 4 bytes for argc for 66 bytes??


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...