Technology

What is the printf() and scanf() functions

printf() and scanf() functions are input, output library functions. But these are available in C library by default. printf and scanf is also called input output statements. These two functions are not defined by the user but it is defined by the compiler. Before these function include in program we have to use stdio.h. Mostly these two functions defined in stdio.h header file. If program consists of printf and scanf function then it is mandatory to include stdio.h.

What is printf function :

Syntax –

printf(“text to be displayed”);

For example – printf(“a is a small letter”);

  • %d is used to display integer value on the output screen.
  • %c is used to display character for float variable.
  • %s used for string variable.
  • %If used for double.
  • %x used for hexadecimal.
  • Also used to generate a new line, use “\n” in C printf() statement.
  • printf() and Printf() are mainly different.

Examples of printf function :

1.

#include<stdio.h>
main()
{
  int n;
  n=10;
  printf(“%d”, n);
}

2. 
#include<stdio.h>
#include<conio.h>
void main() 
{
 clrscr(); 
printf(“Doreamon”); 
getch(); 
}
3.
#include<stdio.h>
#include<conio.h>
void main(){
int a=5
clrscr();
printf(“Enter the value of a = %d”, 5);
getch();
}


What is the scanf function :

scanf() is the input function in C programming language. Standard function reads the formatted input such as keyboard.

Syntax-

scanf(“control string”, &variables);

e.g. scanf(“%d”, &a);

Also it is mostly used to read character, string, and numeric data from keyboard.

Example of scanf :

1. 

#include<stdio.h>
main() 
{
  int n;
  n=10;
  printf("%d", n);
  scanf("%d", &n);
  printf("%d", n);
} 

2.
#include<stdio.h>

#include<conio.h>

void main()
{
int a=5
clrscr();
printf(“Enter the value of a :” );
scanf(“%d”,&a);
printf(“The value of a = %d”, a);
getch();
}



What is the difference between printf and scanf function ?

printf functionscanf function
1. printf is the output function. scanf is the output function.
2. printf stands for print format. 2. scanf stands scan format.
3. printf is used when an integer, character, float, octal, string or hexadecimal value displayed on the output screen. 3. scanf is used to get input information typed from the user.
4. Data types used in printf –
%d – integer
%c – character
%f – float variable
%s – string
%If – double variable
%x – hexadecimal variable
\n – generate a new line
%o – octal value


4. Data types used in scanf –
ch – character
str – string %d – integer %s – string
What is the printf function?

printf function mainly prints the output on the screen such as (character, float, string, octal and hexadecimal values).

What is the function of scanf?

scanf is the standard function which is used to take input from the user. scanf is also read formatted input from the device such as keyboards.

Thank you…

Leave a Reply

Your email address will not be published. Required fields are marked *