Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c string basics, why unassigned?

I am trying to learn the basics, I would think that declaring a char[] and assigning a string to it would work. thanks

int size = 100;
char str[size];

str = "\x80\xbb\x00\xcd";

gives error "incompatible types in assignment". what's wrong? thanks

like image 975
alfo Avatar asked Dec 05 '25 15:12

alfo


1 Answers

You can use a string literal to initialize an array of char, but you can't assign an array of char (any more than you can assign any other array). OTOH, you can assign a pointer, so the following would be allowed:

char *str;

str = "\x80\xbb\x00\xcd";
like image 112
Jerry Coffin Avatar answered Dec 07 '25 05:12

Jerry Coffin