C Input and output in the c programming language is to take input from the user at runtime and output means to print the output to the output screen.

What is C input and output?

The C input and output are the main functions in the c programming language.

What are the input and output?
Input: – It is a process to take user input while executing any program.
Output: – It is the process of printing the statement to the output screen.

In C programming there are the standard libraries which provide a set of inbuilt functions to read any type of input and to display data to the output screen.
The stdio.h or standard input and output libraries in c has various methods for input and output data.

C Input and output functions in c are printf() function and scanf() function.

Standard I/O Library functions in c

  1. prinf() function
  2. scanf() function

printf() function

Printf() is called a Formatted output function in c.
It is the main output function which is used to print data to the output screen.
It processes we here it takes text or value within a program and print it on to the output screen. printf is a function which mainly used to print the text or value of a variable to the screen.

C input and output
printf() function

Syntax for printf(): –
printf(“< Formatted string >”);

The formatted string you want to display must be enclosed within quotes. and the semicolon at the end indicates the end of the statement.

Example: –
print(“Technical seek”);

In the above example we want to print Technical seek statement to the output screen to do this we use printf function in this function we put statement which we want to print in doubt quotes. The printf function interprets compiler to print the text to screen and semicolon ‘;’ at the end indicates the end of the statement.

The printf function uses the same placeholders as:
int uses %d
float uses %f
char uses %c
character strings (discussed later) use %s

scanf() function

It is called as formatted input in c.
It is a process, where we enter the input at runtime and which value is stored to the variable. scanf() function which is used to take the input from user to the variable.

C input and output
scanf() function

Syntax for scanf() function: –
scanf(“placeholder”,&<variable-name>);

Example:-
string name;
printf(“Enter Name”);
scanf(“%s”,&name);

In the above example, we have taken the input from using the value name and stored that name to variable name. scanf function which is used to take the input from users in this function we specify the type of which we taking input (there is a different notation to specify the type of which we taking input .for integer type we write %d,  for float %f, for string %s etc). After, &name indicates to taken value to be stored yo variable name.

The scanf function uses the same placeholders as printf:
int uses %d
float uses %f
char uses %c
character strings (discussed later) use %s

Program for printf and scanf in c

#include <stdio.h>

int main()
{
int no;
printf("Enter value input = ");
scanf("%d",&no); //formatted input
printf("\nOutput value = %d",no); //formatted output

return 0;
}

Output: –

printf and scanfCharacter Input and output

printf and scanf used to take a string input similarly it is possible to take a single character input and to print single character in c.
In c programming standard library functions provides getchar() and putchar() to deal with single character.

Character input and output functions

  1. getchar()
  2. putchar()

getchar() :-

The getchar () function is used to take the input character from the standard input stream.

Syntax: –
getchar();
getchar() returns a character which is a value from input stream.

Example: –
char c = getchar();
printf(“%c”,c);

putchar() :-

The purchase() function is used to print character to output screen.
Syntax: –
putchar(char c);

Example: –
char c = ‘S’;
putchar(c);

Program for getchar putchar in c

#include <stdio.h>

int main()
{
char c;
printf("Enter character = ");
c = getchar();
printf("\n character value = %c",putchar(c)); //formatted output

return 0;
}

Output: –

getchar and putchar

Write A Comment