what is the difference between printf and scanf?
what is the difference between printf and scanf?
Collapse
X
-
Tags: None
-
HI ! printf will print the data you ask from the program to print, like for example if you have an int a, and you have put the value 1 to it, you can write in the program printf("The value of a is: %d\n",a); %d will print the integer after the comma, and the \n will move the cursor a line down after the printing, so you'll have printed:
The value of a is: 1
scanf reads data. For example you can have scanf(“%d”,&k); if you have an int k, before that, and it will read the value of k that the user will give and put it in k.Comment
-
scanf is for taking input from the user. the user input is interpreted as per the format specifier(%c, %d, %u etc) specified. It requires the address of the variable in which the value is to be stored. This is given by &(variable name)
printf is used for displaying data to the user. The output is formatted as per the format specifier used (%c, %d, %u etc).Comment
Comment