Input/Output (I/O) in C programming involves the exchange of data between the program and external sources such as files or the console. It encompasses functions like printf() and scanf() for output and input operations, respectively. Effective utilization of I/O is crucial for interacting with users and managing data efficiently in C programs.
Input is a data which is taking by the user during the execution of program.
Example
#include<stdio.h> int main( ) { int x; scanf("%d",&x); return 0; }Output
Output is the data which is printed in the screen or file or printer.
Example
#include<stdio.h> int main( ) { printf("Small Code"); return 0; }
scanf( ) and printf( ) function comes under the 'stdio.h' header file and its full form is standred input output header file. 'scanf()' are used for taking input from user. 'printf()' are used to print the data in output screen.
Synatx of scanf()
scanf("formet specifier",operends_address);Here 'formet specifier' (%d,%c,%f etc) and 'operends_address' it is the address of the variable.
Synatx of printf()
//With formet specifier printf("formet specifier",operends); //Without formet specifier printf("words or strings");
Here 'formet specifier' (%d,%c,%f etc) and 'operends' either it is variable or values. 'word or strings' specify anythink(like string,char,integer,decimal value,or symboles) expcept keywords and system define statement.
Example
#include<stdio.h> int main( ) { int x; scanf("%d",&x);printf("%d",x); printf("Small Code"); return 0; }
In this example first we declear 'x' variable then taking input from user then print in output line and after then print the string 'Small Code'.
gets() and puts() are used to taking input strings and printing in output screen.It is gernerlly used with pointer variable to take input in one line using gets() function.
Example
#include<stdio.h> #include<string.h> int main( ) { char x[100]; gets(x);puts(x); return 0; }
If we give the input "Small Code is a educational website" then then it gives same output 'Small Code is a educational website'.
'getchar()' function is used to take single character from user at a time. This function returns the character given by the user. 'putchar()' function is used to output single character at a time.
Example
#include<stdio.h> #include<string.h> int main( ) { char x; x=getchar();putchar(x); return 0; }
when the code is compiled then system reqested for the input (any char) then it print same as output screen.
The main difference between scanf and gets is when it takes input it terminated when ' ' first space is come but in gets whole string is takes.In printf and puts when we take input then the statement is comes after space it will not take and that will not printed by 'printf' and in puts whole inputed data will print in one time.