All pastes #734165 Raw Edit

Pointer vs array

public c v1 · immutable
·published 2007-10-12 13:28 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(int argc, char *argv[]){    if (argc == 1) {        printf("Usage: %s [pointer|array]\n", argv[0]);        exit(EXIT_FAILURE);    }    if (strcmp(argv[1], "pointer") == 0) {        char *s = "hello";        s[0] = 'j'; /* This will cause a segfault */        printf("%s\n", s);    }    else if (strcmp(argv[1], "array") == 0) {        char s[] = "hello";        s[0] = 'j';        printf("%s\n", s);    }    exit(EXIT_SUCCESS);}