elibraryportal Logo

Basic Input Output Statement in C

printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).

1) printf() function

Prints the given statement to the console by use of printf() function .

Syntax

Where format string can be %d (integer), %c (character), %s (string), %f (float) etc.

Example:

Output:

Character is A
String is fresh2refresh.com
Float value is 10.234000
Integer value is 150
Double value is 20.123456
Octal value is 226
Hexadecimal value is 96  

2) scanf() function

Read the input value(character, string, numeric data) from the keyword by the use of scanf() function.

Syntax

Example: 1

Output:

Enter a number:5
cube of number is:125

Example: 2

Output:

Enter any character
a
Entered character is a
Enter any string ( upto 100 character )
hai
Entered string is hai   
Next TopicVariables in C