C - Variables and Data TypesYou 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;Check Answer
Step-by-Step SolutionSolution:Step 1: Understand string literals and constString literals are enclosed in double quotes and stored as char arrays. Using const char * prevents modification.Step 2: Check optionsconst 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.Final Answer:const char *msg = "Hello"; -> Option BQuick 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 stringsWrong data types for strings
Master "Variables and Data Types" in C9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More C Quizzes C Basics and Execution Environment - Why C is widely used - Quiz 14medium C Basics and Execution Environment - What is C - Quiz 4medium C Basics and Execution Environment - Structure of a C program - Quiz 9hard C Basics and Execution Environment - Why C is widely used - Quiz 8hard Conditional Statements - If statement - Quiz 7medium Conditional Statements - Nested conditional statements - Quiz 5medium Operators and Expressions - Increment and decrement operators - Quiz 3easy Operators and Expressions - Increment and decrement operators - Quiz 11easy Operators and Expressions - Operator precedence - Quiz 4medium Variables and Data Types - Type modifiers - Quiz 14medium