Dynamic memory

pec_vlog_file = new char[strlen(argv[i+1])+1];

if strlen(argv[i+1])+1 = 50
This code give pec_vlog_file a dynamic memory which is in char type with [50] of free space.Am i right?but what is this for?why we need to assign dynamic memory and do those strlen to get the size?
This code give pec_vlog_file a dynamic memory which is in char type with [50] of free space.Am i right?

Yes.
but what is this for?why we need to assign dynamic memory and do those strlen to get the size?

Presumably, because the size of the memory needed for pec_vlog_file is not known at compile time, because it's based on the length of the string argv. If argv were a different size, then a different amount of memory would be needed for pec_vlog_file.
Last edited on
Topic archived. No new replies allowed.