0% found this document useful (0 votes)
15 views5 pages

Input-Output and Format Specifiers

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

Input-Output and Format Specifiers

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

Input / Output Functions and Format Specifiers:

Input and Output (I/O) are the basic operations of any C program. | Input और Output (I/O)
किसी भी C program की मूलभूत क्रियाएँ हैं।

 Input → Taking data from user. | User से data लेना।


 Output → Displaying result to user. | User को result दिखाना।

C language provides two categories of I/O functions: | C language दो प्रकार के I/O functions
देती है:

1. Formatted Functions
2. Unformatted Functions

Formatted I/O Functions:

Formatted functions can be used for any data type. With the help of these functions, we can
input data of types like integer, double, character, float, string etc. and can also show the
output on the console screen of any type.

Formatted functions use format specifiers, that is why they are called formatted functions.

Examples:

 printf() → output function


 scanf() → input function

(a) scanf() Function

 Declared in stdio.h header file. | stdio.h में declared है।


 Takes input from keyboard and stores it in variables using & (address-of operator). |
Keyboard से input लेकर & ऑपरेटर की मदद से variable में store करता है।
 Returns an int = number of inputted values.

Example:

int a;

scanf("%d", &a);

(b) printf() Function


 Declared in stdio.h. | stdio.h में declared।
 Displays data on screen. | Data को screen पर दिखाता है।
 Returns an int = number of characters printed. | Return value = कितने characters print
हुए।

Example:

int a = 10;

printf("Value = %d", a); // Output → Value = 10

Unformatted I/O Functions

Unformatted functions do not use format specifiers. | Unformatted functions format specifiers
का उपयोग नहीं करती।
They work only with a specific type of data. | ये केवल specific data type पर काम करती हैं।

Examples:

 Input: getch(), getche(), getchar()


 Output: putch(), putchar(), puts()

(a) getch() :

 Declared in conio.h. | conio.h में declared।


 Takes single character input. | Single character input लेता है।
 Does not echo (character screen पर show नहीं होता)। | Input लिया जाता है
लेकिन screen पर नहीं दिखता।
 Returns ASCII value. | ASCII value return करता है।
 Not standard function (कुछ compilers support नहीं करते)।

#include <stdio.h>

#include <conio.h>

int main() {
char ch;

printf("Press any key: ");

ch = getch(); // input लिया लेकिन show नहीं होगा

printf("\nYou pressed: %c", ch);

return 0;

Output (if user presses 'A'):

Press any key:


You pressed: A

(b) getche() :

 Declared in conio.h. | conio.h में declared।


 Takes single character input. | Single character input लेता है।
 Echoes character (screen पर character दिखाई देता है)। | Input के साथ screen पर
show भी होता है।
 Returns ASCII value. | ASCII value return करता है।
 Non-standard function (modern compilers may not support)।

Example:

#include <stdio.h>

#include <conio.h>

int main() {

char ch;

printf("Press any key: ");

ch = getche(); // input लिया और show भी होगा

printf("\nYou pressed: %c", ch);

return 0;
}

Output (if user presses 'A'):

Press any key: A

You pressed: A

(c) getchar() :

 Declared in stdio.h. | stdio.h में declared।


 Standard function (all compilers support). | Standard function (सभी compilers support
करते हैं)।
 Takes one character input and shows it (works like getche()). | एक character input लेकर
show करता है।
 Returns ASCII value.

Example:

#include <stdio.h>

int main() {

char ch;

printf("Enter a character: ");

ch = getchar(); // character input लेता है और show करता है

printf("You entered: %c", ch);

return 0;

Output (if user enters 'B'):

Enter a character: B

You entered: B

(d) putch() :

 Declared in conio.h. | conio.h में declared।


 Prints a single character to screen. | एक character screen पर print करता है।
 Non-standard function. | Non-standard function।

Example:

#include <stdio.h>

#include <conio.h>

int main() {

char ch = 'X';

putch(ch);

return 0;

(e) putchar() Function:

 Standard function for outputting a single character. | एक standard function है single


character print करने का।
 Declared in stdio.h.

Example:

#include <stdio.h>

int main() {

char ch = 'Y';

putchar(ch);

return 0;

You might also like