C Programming/C Basics

C Input & Output

Updated on January 8, 2026
1 min read

Input and Output in C

Input and Output (I/O) in C are used to receive data from the user and display results on the screen. C performs input and output using standard library functions provided in the stdio.h header file.

Input in C

Input means taking data from the user through the keyboard. C uses functions that read data from the standard input stream (stdin).

Common Input Function: scanf()

scanf("%d", &age);
  • Reads input from the keyboard
  • %d specifies the type of input (integer)
  • &age gives the memory address where input is stored

Example:

int age;
scanf("%d", &age);

Output in C

Output means displaying data on the screen. C sends output to the standard output stream (stdout).

Common Output Function: printf()

printf("Age is %d", age);
  • Displays formatted output
  • Uses format specifiers to represent data types
  • Does not require the address operator

Complete Input–Output Program Example

c
1#include <stdio.h>
2
3int main() {
4    int number;
5    printf("Enter a number: ");
6    scanf("%d", &number);
7    printf("You entered: %d", number);
8    return 0;
9}

Format Specifiers

Format specifiers define the type of data being input or output.

SpecifierMeaning
%dInteger
%fFloat
%cCharacter
%sString
%lfDouble

Character Input and Output

C also provides functions for single-character I/O.

char ch;
ch = getchar();
putchar(ch);
  • getchar() reads one character from keyboard
  • putchar() prints one character to screen

Standard Streams in C

C uses three standard streams:

StreamPurpose
stdinInput (keyboard)
stdoutOutput (screen)
stderrError messages

Functions like scanf() and printf() operate on these streams.

Key Differences Between printf() and scanf()

Featureprintfscanf
OperationOutputInput
Uses & operatorNoYes
DirectionProgram → ScreenKeyboard → Program

Important Points

  • Input functions store data into memory
  • Output functions read data from memory and display it
  • Incorrect format specifiers cause runtime errors
  • Proper use of & is essential in input operations

One-Line Exam Answer

Input functions accept data from the user, and output functions display data to the user in a C program.

C Input & Output | C Programming | Learn Syntax