C - Input and OutputWhich of the following is the correct syntax to print a string variable str in C?Aprintf("%s", str);Bprintf("%c", str);Cprintf("%d", str);Dprintf("%f", str);Check Answer
Step-by-Step SolutionSolution:Step 1: Identify the format specifier for stringsThe correct format specifier for strings is %s.Step 2: Match the specifier with the variable type%c is for characters, %d for integers, and %f for floats, so they are incorrect for strings.Final Answer:printf("%s", str); -> Option AQuick Check:String output = %s [OK]Quick Trick: Use %s to print strings in printf [OK]Common Mistakes:Using %c for stringsUsing %d for stringsUsing %f for strings
Master "Input and Output" 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 5medium C Basics and Execution Environment - Compilation process in C - Quiz 12easy C Basics and Execution Environment - Header files and include directive - Quiz 11easy Conditional Statements - Nested conditional statements - Quiz 2easy Conditional Statements - Else–if ladder - Quiz 7medium Input and Output - Using printf for output - Quiz 7medium Input and Output - Why input and output are required - Quiz 3easy Loop Control Statements - Continue statement - Quiz 12easy Operators and Expressions - Ternary operator - Quiz 13medium Variables and Data Types - Basic data types - Quiz 5medium