"๐’๐ก๐š๐ซ๐ข๐ง๐  ๐ค๐ง๐จ๐ฐ๐ฅ๐ž๐๐ ๐ž ๐ข๐ฌ ๐ง๐จ๐ญ ๐š๐›๐จ๐ฎ๐ญ ๐ ๐ข๐ฏ๐ข๐ง๐  ๐ฉ๐ž๐จ๐ฉ๐ฅ๐ž ๐ฌ๐จ๐ฆ๐ž๐ญ๐ก๐ข๐ง๐ , ๐จ๐ซ ๐ ๐ž๐ญ๐ญ๐ข๐ง๐  ๐ฌ๐จ๐ฆ๐ž๐ญ๐ก๐ข๐ง๐  ๐Ÿ๐ซ๐จ๐ฆ ๐ญ๐ก๐ž๐ฆ. ๐“๐ก๐š๐ญ ๐ข๐ฌ ๐จ๐ง๐ฅ๐ฒ ๐ฏ๐š๐ฅ๐ข๐ ๐Ÿ๐จ๐ซ ๐ข๐ง๐Ÿ๐จ๐ซ๐ฆ๐š๐ญ๐ข๐จ๐ง ๐ฌ๐ก๐š๐ซ๐ข๐ง๐ . | Shalu Anand

Post

editor-img
Shalu Anand
Oct 17, 2022

"๐’๐ก๐š๐ซ๐ข๐ง๐  ๐ค๐ง๐จ๐ฐ๐ฅ๐ž๐๐ ๐ž ๐ข๐ฌ ๐ง๐จ๐ญ ๐š๐›๐จ๐ฎ๐ญ ๐ ๐ข๐ฏ๐ข๐ง๐  ๐ฉ๐ž๐จ๐ฉ๐ฅ๐ž ๐ฌ๐จ๐ฆ๐ž๐ญ๐ก๐ข๐ง๐ , ๐จ๐ซ ๐ ๐ž๐ญ๐ญ๐ข๐ง๐  ๐ฌ๐จ๐ฆ๐ž๐ญ๐ก๐ข๐ง๐  ๐Ÿ๐ซ๐จ๐ฆ ๐ญ๐ก๐ž๐ฆ. ๐“๐ก๐š๐ญ ๐ข๐ฌ ๐จ๐ง๐ฅ๐ฒ ๐ฏ๐š๐ฅ๐ข๐ ๐Ÿ๐จ๐ซ ๐ข๐ง๐Ÿ๐จ๐ซ๐ฆ๐š๐ญ๐ข๐จ๐ง ๐ฌ๐ก๐š๐ซ๐ข๐ง๐ .

๐’๐ก๐š๐ซ๐ข๐ง๐  ๐ค๐ง๐จ๐ฐ๐ฅ๐ž๐๐ ๐ž ๐จ๐œ๐œ๐ฎ๐ซ๐ฌ ๐ฐ๐ก๐ž๐ง ๐ฉ๐ž๐จ๐ฉ๐ฅ๐ž ๐š๐ซ๐ž ๐ ๐ž๐ง๐ฎ๐ข๐ง๐ž๐ฅ๐ฒ ๐ข๐ง๐ญ๐ž๐ซ๐ž๐ฌ๐ญ๐ž๐ ๐ข๐ง ๐ก๐ž๐ฅ๐ฉ๐ข๐ง๐  ๐จ๐ง๐ž ๐š๐ง๐จ๐ญ๐ก๐ž๐ซ ๐๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ ๐ง๐ž๐ฐ ๐œ๐š๐ฉ๐š๐œ๐ข๐ญ๐ข๐ž๐ฌ ๐Ÿ๐จ๐ซ ๐š๐œ๐ญ๐ข๐จ๐ง; ๐ข๐ญ ๐ข๐ฌ ๐š๐›๐จ๐ฎ๐ญ ๐œ๐ซ๐ž๐š๐ญ๐ข๐ง๐  ๐ฅ๐ž๐š๐ซ๐ง๐ข๐ง๐  ๐ฉ๐ซ๐จ๐œ๐ž๐ฌ๐ฌ๐ž๐ฌ."

with this,

๐—Ÿ๐—ฒ๐˜'๐˜€ ๐—•๐—ฒ๐—ด๐—ถ๐—ป ๐ฐ๐ข๐ญ๐ก ๐ƒ๐š๐ฒ 8 :

๐šœ๐šŽ๐š›๐š’๐šŽ๐šœ ๐š˜๐š ๐šœ๐š‘๐šŠ๐š›๐š’๐š—๐š ๐š–๐šข ๐š”๐š—๐š˜๐š ๐š•๐šŽ๐š๐š๐šŽ ๐š˜๐š ๐š๐š‘๐šŽ ๐™ฒ ๐™ป๐šŠ๐š—๐š๐šž๐šŠ๐š๐šŽ.

String Literals

A string literal in C is a sequence of chars, terminated by a literal zero.

char* str = "hello, world"; /* string literal */

/* string literals can be used to initialize arrays */

char a1[] = "abc"; /* a1 is char[4] holding {'a','b','c','\0'} */

char a2[4] = "abc"; /* same as a1 */

char a3[3] = "abc"; /* a1 is char[3] holding {'a','b','c'}, missing the '\0' */

String literals are not modifiable (and may be placed in read-only memory such as .rodata). They are attempting to alter their values resulting in undefined behavior.

char* s = "foobar";

s[0] = 'F'; /* undefined behaviour */

/* it's good practice to denote string literals as such, by using `const` */

char const* s1 = "foobar";

s1[0] = 'F'; /* compiler error! */

Multiple string literals are concatenated at compile time, which means you can write construct like these.

/* only two narrows or two wide string literals may be concatenated */

char* s = "Hello, " "World";

/* since C99, more than two can be concatenated */

/* concatenation is implementation-defined */

char* s1 = "Hello" ", " "World";

/* common usages are concatenations of format strings */

char* fmt = "%" PRId16; /* PRId16 macro since C99 */

String literals, the same as character constants, support different character sets.

/* normal string literal, of type char[] */

char* s1 = "abc";

/* wide character string literal, of type wchar_t[] */

wchar_t* s2 = L"abc";

/* UTF-8 string literal, of type char[] */

char* s3 = u8"abc";

/* 16-bit wide string literal, of type char16_t[] */

char16_t* s4 = u"abc";

/* 32-bit wide string literal, of type char32_t[] */

char32_t* s5 = U"abc";