1

Could some one share why below program crashes?

void main() {

    char *arr = "abcd";
    arr[3] = 'f';
}
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
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
  • 58,877
  • 16
  • 101
  • 156