Skip to main content

Printf and Scanf Example in C

1 min read Updated June 30, 2026
Share:
On this page (7sections)

About this program

This is an example program in **data input and output programs in c **. Read the concept first: printf and scanf in C, then study the code and output below.

Definition of Printf And Scanf :

scanf is a function that reads formatted data from stdin.h and then writes the results into the arguments given. The printf built-in function writes output to an implementation.

Synatx:

printf("Text to be displayed : %access_specifiers", variable);

scanf(const char *format, variable);

Example Program for Printf and Scanf:

/*##Printf And Scanf*/
/*##I/O Programs, Basic Programs*/
/*##Example*/

#include <stdio.h>
int main()
{
    char ch;
    char str[100];
    printf(?Enter any character \n?);
    scanf(?%c?, &ch);
    printf(?Entered character is %c \n?, ch);
    printf(?Enter any string ( upto 100 character ) \n?);
    scanf(?%s?, &str);
    printf(?Entered string is %s \n?, str);
}

Sample Output:

Enter any character
a
Entered character is a
Enter any string ( upto 100 character )
hai
Entered string is hai

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C program do?
It is a C example program that demonstrates Printf and Scanf, including the complete source code and the expected sample output.
How do I compile and run this C program?
Save the code in a `.c` file, compile it with `gcc filename.c -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses arrays and reading user input, illustrating a common pattern in C programming.

Related Tutorials

Search tutorials