Which lines will be executed/compiled with errors?
char *s1((char *)("foo"));  //1
char s2[] = "foo";  //2
char *s3 = (char *) new char[10];  //3
s1[2] = 'a';  //4
*s2 = 'b';  //5
3[s3] = 'c';  //6
Explanation
The fourth line tries to change the constant memory area. The sixth line is correct. You can read the details here: Accessing array elements.

The string by array in 2 is atually local variable stored on the stack in ontrast to 1 stored in .data

2023 Dec 26, 6:37:31 AM

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести