0% found this document useful (0 votes)
4 views

xii computer input output

The document explains input and output functions in C, categorizing them into formatted and unformatted functions. Formatted functions like printf() and scanf() handle all data types and require format specifiers, while unformatted functions like getchar() and getch() are specific to certain data types and do not require format strings. Examples of both types of functions are provided to illustrate their usage.

Uploaded by

Free Fire Gamers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

xii computer input output

The document explains input and output functions in C, categorizing them into formatted and unformatted functions. Formatted functions like printf() and scanf() handle all data types and require format specifiers, while unformatted functions like getchar() and getch() are specific to certain data types and do not require format strings. Examples of both types of functions are provided to illustrate their usage.

Uploaded by

Free Fire Gamers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Input / output in c

Input/ Output.
Input and output is achieved through input/ output library functions. There are two types of
input/ output functions. 1. Formatted input/ output functions 2. Unformatted input/output
functions.

Q. What is difference between formatted and unformatted functions in C?


Formatted input and output functions in C Unformatted input and output functions in C
Formatted I/O functions are used for all data Unformatted I/O functions are used only for a
types. E.g. scanf(), printf() particular data type for which it has been
designed. E.g. getch(), puts()
Formatted I/O functions require format string Unformatted I/O functions do not require
(Format Specifier) to produce formatted result. format string (Format Specifier) for formatting
data type.

Q. Define formatted I/O and unformatted I/O functions


Formatted I/O Functions
printf() <stdio.h>
Function printf() stands for “print formatted”. This function is a generalized output function
that can be used to output any data type.
1|Page INPUT / OUTPUT IN C
Syntax:
printf(“control string”, variable list);
Example:
int age=17;
printf(“The age of Salman is %d:”,age);
Output:
The age of Salman is 17 //(%d will be replaced by the variable age)
scanf() <stdio.h>
The scanf() function stands for “scan formatted”. This function is a generalized function
which is used to input all types of data.
Syntax:
scanf(“Control String”, Address of variable);
Example
int x;
scanf(“%d”,&x);
(& is called address operator that invokes the address of variable)
Unformatted I/O Functions for char Data Type
getchar() <stdio.h>
The function getchar() stands for “get character” and inputs a single character from the
keyboard. When called, the function waits for a key to be pressed.
Syntax: char var=getchar();
Example:
char x;
x=getchar();
getch() <conio.h>
getch() stands for “get character”. This function is used to take a single character without waiting
for the confirmation via ENTER KEY. The character that provided by the user is not appeared on
screen, means input character without echo.
Syntax: char var=getch();
Example:
char ch;
ch=getch();
getche() <conio.h>
getche() stands for “get character with echo”. This function is used to take a single character
without waiting for the confirmation via ENTER KEY. The character that provided by the user is
appeared on screen, means input character with echo.
Syntax:
char var=getche();
Example:
char ch;
2|Page INPUT / OUTPUT IN C
ch=getche();

putchar() <stdio.h> and putch() <conio.h>


The functions putchar() and putch() stands for “put character” and displays only a single
char value on the screen. The data can be provided as char variable or as char constant. The
working of both functions is identical only header file is different.
Syntax:
putchar(char var or char constant);
Example:
char x=’A’;
putchar(x);
putchar(‘Z’);
Unformatted I/O Functions for string Data Type
gets() <string.h>
The function gets() stands for “get string”. It reads the string from the keyboard, adds the null
character ‘\0’ at the end of it, and assigns it to a required variable which comes as an argument of
the function.
Syntax:
gets(character array);
Example:
char name[15];
gets(name);
puts() <string.h>
The function puts() stands for “put string” and displays a string on monitor. String is
provided as an argument.
Syntax:
puts(char array or string constant);
Example
char name[]=“Bahria College”;
puts(name);

3|Page INPUT / OUTPUT IN C

You might also like