C Tutorial



INPUT OUTPUT IN C


Input & Output in C

In C, we use functions from the stdio.h library to take input from the user and display output on the screen.

πŸ“˜ Key Functions: printf() for output and scanf() for input.

πŸ–¨οΈ Output Using printf()

The printf() function is used to display text and variable values.

#include <stdio.h>

int main() {
    printf("Welcome to C Programming!");
    return 0;
}
  

🎯 Input Using scanf()

The scanf() function is used to take input from the user.

#include <stdio.h>

int main() {
    int age;
    printf("Enter your age: ");
    scanf("%d", &age);
    printf("You are %d years old.", age);
    return 0;
}
  

πŸ“Œ Format Specifiers

  • %d β†’ for int
  • %f β†’ for float
  • %c β†’ for char
  • %s β†’ for strings
πŸ’‘ Note: Always use & (address-of operator) in scanf() for variables.

πŸ“ Try It Yourself

  1. Take input of a user's name and age.
  2. Display: β€œHello [Name], you are [Age] years old.”

❌ Common Mistakes

  • 🚫 Forgetting & in scanf()
  • 🚫 Mismatched format specifiers and variable types

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review