string manipulations in C
Posted
by
Vivek27
on Stack Overflow
See other posts from Stack Overflow
or by Vivek27
Published on 2012-10-05T09:28:31Z
Indexed on
2012/10/05
9:37 UTC
Read the original article
Hit count: 208
Following are some basic questions that I have with respect to strings in C.
- If string literals are stored in read-only data segment and cannot be changed after initialisation, then what is the difference between the following two initialisations.
char *string = "Hello world";
const char *string = "Hello world";
- When we dynamically allocate memory for strings, I see the following allocation is capable enough to hold a string of arbitary length.Though this allocation work, I undersand/beleive that it is always good practice to allocate the actual size of actual string rather than the size of data type.Please guide on proper usage of dynamic allocation for strings.
char *string = (char *)malloc(sizeof(char));
© Stack Overflow or respective owner