Categories:
.NET (961)
C (387)
C++ (185)
CSS (84)
DBA (8)
General (31)
HTML (48)
Java (641)
JavaScript (220)
JSP (109)
JUnit (31)
MySQL (297)
Networking (10)
Oracle (562)
Perl (48)
Perl (9)
PHP (259)
PL/SQL (140)
RSS (51)
Software QA (28)
SQL Server (5)
Struts (20)
Unix (2)
Windows (3)
XHTML (199)
XML (59)
Other Resources:
What is the difference between these initializations? ....
What is the difference between these initializations?
char a[] = "string literal";
char *p = "string literal";
My program crashes if I try to assign a new value to p[i].
✍: Guest
A string literal (the formal term for a double-quoted string in C source) can be used in two slightly different ways:
1. As the initializer for an array of char, as in the declaration of char a[] , it specifies the initial values of the characters in that array (and, if necessary, its size).
2. Anywhere else, it turns into an unnamed, static array of characters, and this unnamed array may be stored in read-only memory, and which therefore cannot necessarily be modified. In an expression context, the array is converted at once to a pointer, as usual 2. , so the second declaration initializes p to point to the unnamed array's first element.
Some compilers have a switch controlling whether string literals are writable or not (for compiling old code), and some may have options to cause string literals to be formally treated as arrays of const char (for better error catching).
2016-03-09, 1040👍, 0💬
Popular Posts:
Explain simple Walk through of XmlReader ? In this section we will do a simple walkthrough of how to...
How To Manage Transaction Isolation Level? - Oracle DBA FAQ - Introduction to PL/SQL Transaction iso...
How can you raise custom errors from stored procedure ? The RAISERROR statement is used to produce a...
How To Apply Filtering Criteria at Group Level? - MySQL FAQs - SQL SELECT Query Statements with GROU...
What is the difference between Class and structure’s ? Following are the key differences between the...