Modu
operators and expressions i
By: RISHI KU
, ➢ scanf() function to take input from the user and printf() func
display output to the user.
➢ scanf() and printf() functions are inbuilt library functions in
programming language which are available in C library by de
➢ These functions are declared and related macros are defined
“stdio.h” which is a header file in C language.
➢ We have to include “stdio.h” file as shown in all C program
use of these scanf() and printf() library functions in C languag
C Input and optional for some compilers ).
➢ Key points to remember in C scanf() and printf():
Output (I/O)
➢ scanf() is used to read the formated inputs and printf() is u
display the formatted output.
➢ scanf() and printf() functions are declared and defined in
“stdio.h” header file in C library.
➢ All syntax in C language including scanf() and printf() fu
are case sensitive.
, scanf() Function in C Language
➢ In C programming language, scanf() #include <stdio.h>
function is used to read character, string, int main()
{
numeric data from keyboard. char ch;
char str[100];
➢ scanf(“format string”, argument_list); i.e. printf("Enter any character \n");
scanf(“%format_specifier”, scanf("%c", &ch);
printf("Entered character is %c \n", ch);
&Variable_Name); printf("Enter any string ( upto 100 character ) \n")
scanf("%s", &str);
➢ Consider aside example program where printf("Entered string is %s \n", str);
user enters a character. This value is }
assigned to the variable “ch” and then ▪ The format specifier %d is used in scanf() statem
the value entered is received as an integer and %
displayed. ▪ Ampersand is used before variable name “ch” in
➢ Then, user enters a string and this value is statement as &ch.
assigned to the variable “str” and then
displayed.
operators and expressions i
By: RISHI KU
, ➢ scanf() function to take input from the user and printf() func
display output to the user.
➢ scanf() and printf() functions are inbuilt library functions in
programming language which are available in C library by de
➢ These functions are declared and related macros are defined
“stdio.h” which is a header file in C language.
➢ We have to include “stdio.h” file as shown in all C program
use of these scanf() and printf() library functions in C languag
C Input and optional for some compilers ).
➢ Key points to remember in C scanf() and printf():
Output (I/O)
➢ scanf() is used to read the formated inputs and printf() is u
display the formatted output.
➢ scanf() and printf() functions are declared and defined in
“stdio.h” header file in C library.
➢ All syntax in C language including scanf() and printf() fu
are case sensitive.
, scanf() Function in C Language
➢ In C programming language, scanf() #include <stdio.h>
function is used to read character, string, int main()
{
numeric data from keyboard. char ch;
char str[100];
➢ scanf(“format string”, argument_list); i.e. printf("Enter any character \n");
scanf(“%format_specifier”, scanf("%c", &ch);
printf("Entered character is %c \n", ch);
&Variable_Name); printf("Enter any string ( upto 100 character ) \n")
scanf("%s", &str);
➢ Consider aside example program where printf("Entered string is %s \n", str);
user enters a character. This value is }
assigned to the variable “ch” and then ▪ The format specifier %d is used in scanf() statem
the value entered is received as an integer and %
displayed. ▪ Ampersand is used before variable name “ch” in
➢ Then, user enters a string and this value is statement as &ch.
assigned to the variable “str” and then
displayed.