0% found this document useful (0 votes)
2 views2 pages

CST Assignment Added Question

The document outlines formatted and unformatted I/O functions in C programming. It details the usage of 'printf()' and 'scanf()' for formatted output and input, as well as 'getchar()' and 'putchar()' for unformatted input and output. Each function is accompanied by a usage example demonstrating its application.

Uploaded by

audiolibrary987
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)
2 views2 pages

CST Assignment Added Question

The document outlines formatted and unformatted I/O functions in C programming. It details the usage of 'printf()' and 'scanf()' for formatted output and input, as well as 'getchar()' and 'putchar()' for unformatted input and output. Each function is accompanied by a usage example demonstrating its application.

Uploaded by

audiolibrary987
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/ 2

1.

Formatted I/O Functions


a) printf()
Purpose: Outputs formatted data to the standard output
(console).
Usage Example:
#include <stdio.h>
int main(void) {
int x = 42;
printf("The answer is %d\n", x);
return 0;
}

b) scanf()
Purpose: Reads formatted input from the standard input
(keyboard).
Usage Example:
#include <stdio.h>
int main(void) {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old\n", age);
return 0;
}
2. Unformatted I/O Functions
a) getchar()
Purpose: Reads the next character (as an unsigned char cast to
int) from standard input, without any format parsing.
Usage Example:
#include <stdio.h>
int main(void) {
int c;
printf("Press a key: ");
c = getchar(); // no format string
printf("You pressed: %c\n", c);
return 0;
}

b) putchar()
Purpose: Writes a single character (given as an int) to standard
output.
Usage Example:
#include <stdio.h>
int main(void) {
char ch = 'A';
putchar(ch); // no format string
putchar('\n');
return 0;}

You might also like