Output function :- printf()printf():-
it is a pre-define function means it has reserve in c library to perform output function , it get value from memory and give output to the screen.
- The data stored in memory location will be in machine language (0101010).
- The data stored in memory locations have to be converted into appropriate data type such as integer or floating point number and than convert data can be displayed on the screen for human understanding in the proper format
- All the above activities can be done in c language using the function printf().
The function printf() is the combination of print+f=printf()Print :-
print function prints the data stored in variables to the screen. F – format :-
the data present in memory or variables is read and formatted means converted into appropriate data type. This is done using format string with the help of conversion code that are define in c library .
Syntax of printf() function
Printf(“format string” , list of variables); Example:-
hear %d is a format string and a is a variable
Format String in c
The format string is enclosed within two double quotes “…….” The format string may contain:
- The sequence of characters to be displayed on the screen. Example :- printf(“ok”);
- It may also contain zero or more format specifiers . A format specifier start with % and followed by conversion code . Example :- printf(“%d”,a);
input function :-scanf()
scanf is a function that reads formatted data from input stream, which is usually the keyboard,
- The data entered from the keyboard will be treated as sequence of characters
- If we enter integer data such as 1 2 3 4 5 6 ……. or floating point number such as 2.5 etc they are teated as sequence of characters.
- These sequence of characters entered from the keyboard are stored in fixed memory locations called buffer. The data stored in buffer may have to be converted into appropriate data type such as integer or floating point number etc and then converted data has to be stored in main memory at the location specified by variables.
- All above activities can be done in c using function scanf(). But it always accepts address of variable as argument.
Syntax of scanf() function
scanf(“format string” , list of variables);Example:-