Sunday, June 19, 2016

deprecated conversion from string constant to ‘char*’

How to get rid of compiler error-
deprecated conversion from string constant to ‘char*’
I got this compilation error while compiling the below code.

void ABC(char *strng) {};
ABC("Hello World");
void ABC(char *strng){};               //This code may compile but the window will crash on execution
char *strng1="Hellow World";

I find two solution for this...
void ABC(char *strng){};
char strng1[] ="Hellow World";

2. define const every where if the sting does no changes.
void ABC(const char *strng){};
const char *strng1 ="Hellow World";

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

No comments:

Post a Comment