Why im getting an error? | Sololearn: Learn to code for FREE!


Why im getting an error?

int main () { char *some[]={ "word", "another", "qwerty" }; the error is: cant make const * char for char variable (sorry for bad english ) btw it compiles perfectly if i do this in online compiler


12/8/2021 9:56:52 AM


10 Answers

New Answer


Because "word", "another", and "qwerty" are all string litterals You can only read them, but you cannot write, so they have type 'const char[N]' But you're pointing to them without the const qualifier, which implies you could modify them in the future To solve this just put 'const' before char


Define it as const string array ... const char* some[] = { ... };


try closing the main function with a bracket.


nvm i got it. Thank you guys!


Artur, In Code Playground, I only get such warning about const char* when I pasted (and ran) the snippet into a C++ code, there's no warning if I pasted the code into a C code. The warning given by C++ compiler mentioned about C++ ISO standard, so it seems to be a C++ standard, not adopted in C standard. Dunno about VS 2019, or why it differs from your installation and your friend's ...


Visual studio 2019 failed it, however the online version of C ( on this site ) allowed it. also i tried this code on my friends pc ( VS2019 as well ) and it worked.


Angelo, i may be wrong, but if i put "const" i cant redact this array later?


sorry i can't understand... yet, so sad😥