C printf and Scanf
Input-Output functions in C Programming
In C Language, the printf() and scanf() are inbuilt library functions that used for input and output. It is defined in the header file“<stdio.h>”. printf() Function: In C programming language, printf() function is used to print the values. The values may be character, string,float,integer etc. We can use different types of format specifier to display the value of the program.Format Specifier | Description |
%d | It is used to print the value of integer variable. |
%s | It is used to print the value of string variable. |
%c | It is used to print the value of single character variable. |
%f | It is used to print the value of float variable. |
%lf | It is used to print the value of double variable. |
%x | It is used to print the octal value of integer variable. |
%o | It is used to print the hexadecimal value of integer variable. |
\n | It is used to break the new line. |
Note: C language is the case sensitive. All characters in printf() and scanf() functions must be in lower case.Example of printf() function:
#include <stdio.h> void main() { int a= 5; char ch='A'; float f=7.9; char str[20]="Hello-world"; printf("Integer Value of a: %d \n",a ); printf("single char value of ch:%c\n",ch); printf("Float Value of f: %f \n",f); printf("string value str: %s\n",str); }
scanf() Function:
In C program, scanf() function is used to read character, string, numeric data from the keyboard.