Input and Output Functions in C

Input function:

In the C programing language, the input is directed by the scanf function which is used to take input from the user. It basically reads formatted input from standard input for ex: keyboard.

Syntax Of scanf():

scanf("format-string",&reference-variable);

So, to take input from the user there are certain format specifiers provided which works in the scanf function, they are:

int %d
char%c
float%f
double%lf
short int%hd
unsigned int%u
long int%li
long long int%lli
unsigned long int%lu
unsigned long long int%llu
signed char%c
unsigned char%c
long double%lf
Data-Types And Format Strings

Output function:

In the C programing language, the output function is directed by the printf function which returns an output as directed in the program. The printf function also takes the format specifiers to show the value of the variable in the output section.

Syntax of printf():

//For print statements
printf("statements without variable.");
//For print variables
printf("format-strings",name-of-variable-to-print);

Examples for input and output functions:

Integer:

#include<stdio.h>
int main()
{
	int a;
	printf("Enter an Integer value");
	scanf("%d",&a);
	printf("The value of the Integer %d",a);
	return 0;
}

Here, integer input and output function works on the %d format specifier.

dCJPe5CJCmIMeNCY2GNp1CbwuF7LFanOKzSMXjdrJRxxIHwiTAXIWCDqcBewz4VhgUaq yiSBfenl QAdb3NKoaAPDLNGXVypAQp1eTk j kelEdvJBK3KSwdW46uz2ZnJiK3w

Screenshot Provided By Soham Malakar

Float:

#include<stdio.h>
int main()
{
	float a;
	printf("Enter an float value");
	scanf("%f",&a);
	printf("The value of the float %f",a);
	return 0;
}

Here, float input and output function works with %f format specifier.

7TNX0dEdTCeU63unaf R5DvJtHbrtQWAby9WLs3nLJFg28evs8juAg7SsbXIKJmSmtrk9HydxjAe3Re

Screenshot Provided By Soham Malakar

Char:

#include<stdio.h>
int main()
{
	char a;
	printf("Enter an char value");
	scanf("%c",&a);
	printf("The value of the char %c",a);
	return 0;
}

Here, the char input and output function works with %c format specifier.

Screenshot Provided By Soham Malakar

Double:

#include<stdio.h>
int main()
{
	double a;
	printf("Enter an double value");
	scanf("%lf",&a);
	printf("The value of the double %lf",a);
	return 0;
}

Here, the double input and output function works with %lf format specifier.

dPEBFR0shEE7QbJiYgOsbimopRMBgoSWZhd

Screenshot Provided By Soham Malakar

We can also use the above data type in a single program i.e. we can use multiple input and output functions. For example:

#include<stdio.h>
int main()
{
	int a;
	char b;
	double c;
	float d;
	printf("Enter the value of char variable");
	scanf("%c",&b);
	printf("Enter the value of integer variable");
	scanf("%d",&a);
	printf("Enter the value of double variable");
	scanf("%lf",&c);
	printf("Enter the value of float variable");
	scanf("%f",&d);
	printf("\nThe value of integer variable %d",a);
	printf("\nThe value of char variable %c",b);
	printf("\nThe value of double variable %lf",c);
	printf("\nThe value of float variable %f",d);
	return 0;
}

lcuY2kQZ0wjP 6DPma2 B7f6 eadaMupylt Nc3191J2vJuioCN1cyMidkf0uYQgy wf5ovDg7kz2w0416jN6GMo9mHP58DFsKooQcpMFac4yFq0Rd70TeSqb7mzdsnyB aufg

Screenshot Provided By Soham Malakar

Hence we come to the end of the discussion on input and output functions in the C language. Hope your doubts have been cleared.

Please write comments or WhatsApp if you find anything incorrect, or you want to share more information about the topic discussed above.

Default image
Soham Malakar
Hello my name is Soham Malakar am currently pursuing BCA Coding is one of my favorite hobbies. I love to code and an enthusiast to learn different types of programming languages. I love to get intoxicated in the world of technology and video games. A quick learner possessing better results.
Articles: 15

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply