From 26f4f6b02bd13fc657d32ae21268b25441b40125 Mon Sep 17 00:00:00 2001 From: aditya singh rawat <80266913+unreal0901@users.noreply.github.com> Date: Sat, 18 Feb 2023 11:12:46 -0800 Subject: [PATCH] Added String literals Added a another way to make string that is using character pointer, modifying string literal show undefined behavior. --- source/_posts/c.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/_posts/c.md b/source/_posts/c.md index 0910149..15ed16a 100644 --- a/source/_posts/c.md +++ b/source/_posts/c.md @@ -185,6 +185,14 @@ printf("%s", greetings); // print "Hell!" ``` +Creating String using character pointer (String Literals) +```c +char *greetings = "Hello"; +printf("%s", greetings); +// print "Hello!" +``` +**NOTE**: String literals might be stored in read-only section of memory. Modifying a string literal invokes undefined behavior. You can't modify it.! + `C` **does not** have a String type, use `char` type and create an `array` of characters