printf and scanf in C
0 396
Printf() and scanf() are essential elements in C for Input and Output Operations.
Both functions utilize formatted specifiers to structure the data.
printf()
printf is a function in C that assists in showing information on the screen.
It is used to display text, variables, and numbers in a specific format.
Syntax of printf():printf( const char *format, ....);Example:
#include<stdio.h>
int main()
{
printf("Hello, C Programming Language");
return 0;
}
Output:
Hello, C Programming Language
scanf()
scanf() is a function in C that allows you to get Input From User.
It pauses until the user types something on the keyboard and then saves it in a variable for later use in the program.
It is a fundamental function in C to read the Input from the user.
Syntax of scanf():scanf("format specifier", &variable); // &variable refers to memory address of variable
Format specifiers are as follows:
1'%d ' is used to read the Integer From Input.
2'%c' is used to read a Single Character from the user.
3'%f' is used to read the Floating Point Number Input.
4'%u' is used to read an Unsigned Integer from the input.
For more details refer https://www.codingtag.com/format-specifiers-in-c
Example:
// Example of printf and scanf
#include<stdio.h>
int main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
printf("number is %d",num);
return 0;
}
Output:
Enter the number:12
number is 12
Share:
Comments
Waiting for your comments