bscodinglab

Basic input / Output

In C programming language, there are several functions that are used to handle input and output operations.

Thare are two basic input/output functions 

1 .  Printf() :-

This function is used to print output on the console or command prompt. It takes one or more arguments and prints them to the console. The syntax of printf() function is as follows:

Syntex  –>   printf(“format string”, argument1, argument2, …);

The format string specifies how the arguments will be formatted and printed on the console. For example, to print an integer and a string on the console, you can use the following printf() statement:

Example –>     int num = 5;

                           char str[] = “Hello”;

                          printf(“The number is %d and the string is %s”, num, str);

 

2 .  Scanf() :- 

This function is used to read input from the user. It reads input from the  console and stores it in variables. The syntax of scanf() function is as follows:

     Syntex –>  scanf(“format string”, &variable1, &variable2, …);

The format string specifies how the input will be read and stored in variables. For example, to read an integer and a string from the user, you can use the following scanf() statement:

Example –>      int num;

                            char str[20];

                             scanf(“%d %s”, &num, str);

This statement reads an integer and a string from the user and stores them in variables num and str, respectively.

Note :- that the ampersand (&) is used to get the memory address of the variable in the scanf() statement, which is required to store the user input in the variable