{ A destination to learn coding }

printf and scanf


printf()

printf is used to print the content on the screen.

Syntax:
printf("Hello World");
Code
#include<stdio.h>
int main()
{
int a=20;
printf("The value of a is %d",a);

float b=5.4;
printf("The value of b is %f",b);

char c='a';
printf("The value of c is %c",c);

return 0;
}
		

printf("The value of a is %d",a);
In the above line %d tells printf that the argument has to be treated as an integer.

",a" tells printf to take the integer value from a.

Similarly in the subsequent lines of code, %f and %c tells printf that the arguments have to be treated as floating-point and character respectively.

Note: Note: The character values should always be enclosed in the single quotes. (as shown in the code above)

scanf()

scanf is used to accept the user input. This stores the values into the variables.
Syntax:
scanf("%d",&a);

%d tells scanf that the value to be accepted is of integer type.

&a tells the scanf that the value entered by the user should be assigned to variable a.

(Or in other words) It specifies the address to which the value must be saved.
Note: a should be declared before its use

You can use the knowledge of data types, variables, printf and scanf to write small programmes. All the best.

C Codes