+ 7

Why there is an error at line foo[0]=1? Should it be foo[0]="1"?

include <stdio.h> int main() { const char* foo="hi"; foo="hello"; foo[0]=1; return 0; }

27th Jan 2019, 6:37 PM
Zhenis Otarbay
Zhenis Otarbay - avatar
2 Answers
+ 5
You declared foo as pointing to a const char, so you can't change it.
27th Jan 2019, 6:41 PM
nobody
+ 2
foo is an const char array, so firstly you can’t change it, and secondly 1 is not a char; it is an integer, so there will be errors.
27th Jan 2019, 11:35 PM
Rowsej
Rowsej - avatar