+ 1
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
10 Respostas
+ 7
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
+ 4
Define it as const string array ...
const char* some[] = { ... };
+ 3
try closing the main function with a bracket.
+ 2
nvm i got it. Thank you guys!
+ 2
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 ...
+ 1
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.
0
Angelo, i may be wrong, but if i put "const" i cant redact this array later?
- 1
sorry i can't understand... yet, so sad😥