Bird
0
0

You want to write a C program that prints your name and age on separate lines. Which code snippet correctly does this?

hard📝 Application Q8 of 15
C - Basics and Execution Environment
You want to write a C program that prints your name and age on separate lines. Which code snippet correctly does this?
A#include <stdio.h> int main() { printf("Name: Alice\n"); printf("Age: 25"); }
B#include <stdio.h> int main() { printf("Name: Alice Age: 25"); return 0; }
C#include <stdio.h> void main() { printf("Name: Alice\nAge: 25\n"); }
D#include <stdio.h> int main() { printf("Name: Alice\nAge: 25\n"); return 0; }
Step-by-Step Solution
Solution:
  1. Step 1: Check for correct main function and return type

    #include <stdio.h> int main() { printf("Name: Alice\nAge: 25\n"); return 0; } uses int main() and returns 0, which is standard and correct.
  2. Step 2: Verify output formatting with new lines

    #include <stdio.h> int main() { printf("Name: Alice\nAge: 25\n"); return 0; } prints both name and age on separate lines using \n inside one printf.
  3. Final Answer:

    #include <stdio.h> int main() { printf("Name: Alice\nAge: 25\n"); return 0; } -> Option D
  4. Quick Check:

    #include <stdio.h> int main() { printf("Name: Alice\nAge: 25\n"); return 0; } [OK]
Quick Trick: Use \n inside strings to print on new lines [OK]
Common Mistakes:
  • Using void main instead of int main
  • Missing new line characters
  • Printing all info in one line

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes