c - Difference between assigning strings -
in c tried assign sting variable in 2 different ways
char question[200]; strcpy( question, "this question" );
and
char question[] = "this question";
and both works... what's difference between these 2 methods?
the difference flexibility. this
strcpy( question, "this question" );
you can anytime after declare variable. whereas this:
char question[] = "this question";
you have use directly during declaration time.
in second example length of question
got fixed length of text +1 null terminator. can't change length of variable later, can't assign larger string example.
Comments
Post a Comment