How to declare read only string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main(void) {
    const char* str = "C Programming";

    puts(str);

    // str[3] = 'X'; // error: assignment of read-only location '*(str + 3u)'

    return 0;
}




/*
run:

C Programming

*/

 



answered Feb 25, 2022 by avibootz
...