Input and Output in C

📘 C 👁 37 views 📅 Dec 22, 2025
⏱ Estimated reading time: 1 min

Input and Output (I/O) operations in C are used to accept data from the user and display output to the screen.
C provides standard I/O functions through the stdio.h header file.


Standard Input and Output Functions

Output Function

  • printf() – Displays output on the screen

Input Function

  • scanf() – Reads input from the user


printf() Function

Used to display output.

Syntax

printf("format string", variables);

Example

printf("Hello World"); printf("Age = %d", age);

scanf() Function

Used to take input from the user.

Syntax

scanf("format string", &variable);

Example

scanf("%d", &age);

Format Specifiers

SpecifierMeaning
%dInteger
%fFloat
%lfDouble
%cCharacter
%sString

Example Program (Input and Output)

#include int main() { int age; float salary; printf("Enter age: "); scanf("%d", &age); printf("Enter salary: "); scanf("%f", &salary); printf("Age = %d\nSalary = %.2f", age, salary); return 0; }

getchar() and putchar()

getchar()

  • Reads a single character

char ch; ch = getchar();

putchar()

  • Displays a single character

putchar(ch);

gets() and puts() (Basic understanding)

  • gets() – Reads a string (unsafe, not recommended)

  • puts() – Displays a string


Summary

  • stdio.h provides I/O functions

  • printf() outputs data

  • scanf() inputs data

  • Format specifiers define data type

  • & is used to store input in variables


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes