Input
output statements in c
ANSI standard has defined many library functions for input and output in C language. Functionsprintf() and scanf() are the most commonly used to display out and take input respectively. Let us consider an example:
#include <stdio.h> //This is needed to run printf() function.
int main()
{
printf("Hello World"); //displays the content inside quotation
return 0;
}
Output
Hello World
Explanation of How this program works:
1. Every program starts from main() function.
2. printf() is a library function to display output which only works if #include<stdio.h>is included at the beginning.
3. Here, stdio.h is a header file (standard input output header file) and #include is command to paste the code from the header file when necessary. When compiler encounters printf()function and doesn't find stdio.h header file, compiler shows error.
4. Code return 0; indicates the end of program. You can ignore this statement but, it is good programming practice to use return 0;.
scanf()
I/O of integers in C
ANSI standard has defined many library functions for input and output in C language. Functionsprintf() and scanf() are the most commonly used to display out and take input respectively. Let us consider an example:
#include <stdio.h> //This is needed to run printf() function.
int main()
{
printf("Hello World"); //displays the content inside quotation
return 0;
}
Output
Hello World
Explanation of How this program works:
1. Every program starts from main() function.
2. printf() is a library function to display output which only works if #include<stdio.h>is included at the beginning.
3. Here, stdio.h is a header file (standard input output header file) and #include is command to paste the code from the header file when necessary. When compiler encounters printf()function and doesn't find stdio.h header file, compiler shows error.
4. Code return 0; indicates the end of program. You can ignore this statement but, it is good programming practice to use return 0;.
A terminal keyboard and monitor can be associated
only with a text stream. A keyboard is a
source
for a text stream; a monitor is a destination
for a text stream.
We have :
int qty=23;
float sum=48.53f;
scanf()
I/O of integers in C
No comments:
Post a Comment