c - How table of strings works? -


i searching code didn't believe works, found in books table of strings exists in compiler.

char *p; p = "something";  printf("%s", p); 

how code works ?

"something" string literal, null-terminated character array stored in read-only memory. p pointer char. since set pointer point @ read-only memory, should declare const char*.

sizeof(p) gives size of p. p pointer size of pointer, 4 bytes on specific system.

had instead declared array char arr[] = "something"; have gotten copy of stored in local array, can modify it. , if take sizeof array, expected size. in array case sizeof(arr) give 9+1=10 bytes.

for reference, please read:

what difference between char s[] , char *s?

why segmentation fault when writing string initialized "char *s" not "char s[]"?


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -