1

Could some one share why below program crashes?

void main() {

    char *arr = "abcd";
    arr[3] = 'f';
}
Yu Hao
  • 115,525
  • 42
  • 225
  • 281
user505669
  • 59
  • 5

1 Answers1

3

There is a difference between char * and char []! So this should work:

#include <stdio.h>

int main() {

    char arr[] = "abcd";
    arr[3] = 'f';

    return 0;
}

For further information see:

What is the difference between char s[] and char *s?

Community
  • 1
  • 1
Rizier123
  • 57,440
  • 16
  • 89
  • 140