C

by Vasil Kolev

I started wondering some days ago, can most programmers tell what’s the difference between these three fragments and what can/can’t be done in each case? I can’t remember being taught this:

Fragment 1:

char *pesho=”PESHO”;

Fragment 2:

char *pesho=(char *) malloc (6);
strcpy(pesho,”PESHO”);

Fragment 3:

char pesho[6]=”PESHO”;

(for example, how in one of these cases we must not write in the string, how the other one can’t be returned as a function result, etc.).

Leave a Reply