Bird
0
0

You want to define a constant string literal for the message "Hello" in C. Which is the correct way?

hard📝 Application Q8 of 15
C - Variables and Data Types
You want to define a constant string literal for the message "Hello" in C. Which is the correct way?
Achar msg = 'Hello';
Bconst char *msg = "Hello";
Cconst int msg = "Hello";
Dchar *msg = Hello;
Step-by-Step Solution
Solution:
  1. Step 1: Understand string literals and const

    String literals are enclosed in double quotes and stored as char arrays. Using const char * prevents modification.
  2. Step 2: Check options

    const char *msg = "Hello"; correctly declares a pointer to constant char string. char msg = 'Hello'; uses single quotes and char type incorrectly. const int msg = "Hello"; mismatches type. char *msg = Hello; lacks quotes around Hello.
  3. Final Answer:

    const char *msg = "Hello"; -> Option B
  4. Quick Check:

    String literals use double quotes and const char * [OK]
Quick Trick: Use const char * for constant strings [OK]
Common Mistakes:
  • Using single quotes for strings
  • Wrong data types for strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes