Basic Input/Output Statement

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484

C language has standard libraries that allow input and output in a program. The stdio.h or standard input output library in C that has methods for input and output.

scanf()

The scanf() method, in C, reads the value from the console as per the type specified.

Syntax:

scanf(“%X”, &variableOfXType);

where %X is the format specifier in C. It is a way to tell the compiler what type of data is in a variable

and

& is the address operator in C, which tells the compiler to change the real value of this variable, stored at this address in the memory.

printf()

The printf() method, in C, prints the value passed as the parameter to it, on the console screen.

Syntax:

printf(“%X”, variableOfXType);

where %X is the format specifier in C. It is a way to tell the jcompiler what type of data is in a variable

and

& is the address operator in C, which tells the compiler to change the real value of this variable, stored at this address in the memory.

How to take input and output of basic types in C?

The basic type in C includes types like int, float, char, etc. Inorder to input or output the specific type, the X in the above syntax is changed with the specific format specifier of that type.

The Syntax for input and output for these are:

o    Input: scanf("%d", &intVariable);
o    Output: printf("%d", intVariable);
o    Input: scanf("%f", &floatVariable);
o    Output: printf("%f", floatVariable);
o    Input: scanf("%c", &charVariable);
o    Output: printf("%c", charVariable);

 

C Language Video

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484