Input and Output
Introduction to C
Structure of a C Program
Variables and Data Types
Input and Output
Operators in C
Decision Making
If Statement
if...else Statement
Nested if Statement
Nested if...else Statement
Switch Statement
Loops
For Loop
While Loop
Do While Loop
Loop Comparison
Arrays
Strings
Functions
Function Types
Library Functions
User-Defined Functions
Recursion Function
Pointers
Structures
File Handling
Common Mistakes
Ideas
Input and Output
To interact with users, C uses standard library functions: printf() to display information (Output) and scanf() to receive information (Input).
Practical Example: Reading User Input
#include <stdio.h> int main() { int number; // Asking the user for input printf("Enter a number: "); // Reading and storing the input scanf("%d", &number); // Displaying the stored value printf("You entered: %d\n", number); return 0; }
Deep Dive: How it Works
-
scanf(): This function pauses the program and waits for the user to type something on the keyboard. -
The Ampersand (
&number): This is the address-of operator. It tells C the exact location in the computer's memory where the user's input should be saved. - Format Specifiers: These act as placeholders that tell the compiler what type of data to expect.
| Specifier | Data Type |
|---|---|
%d |
Integers (Whole numbers) |
%f |
Float (Decimal numbers) |
%c |
Char (Single characters) |
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Input and Output to test your knowledge.
Browse Quizzes »