C Program Output - printf() scanf()

printf() and scanf() are two important functions in the C programming language. printf() is used to display output on the console, while scanf() is used to read input from the user. In this tutorial, we will learn how to use these functions with examples, output and explanations.

You can use printf() function to output values or print the text in C. The syntax of printf() function is as follows:

Here, "format string" is the string that we want to display on the console, and the arguments are the values that we want to display along with the string. The format string contains placeholders that are replaced by the values of the arguments.

Example 1:

Output:

Explanation:

In the above example, we have declared an integer variable named "age" and assigned it the value of 25. We have then used printf() function to display the string "My age is " followed by the value of the variable "age". The "%d" is a placeholder for integer values.

Example 2:

Output:

Explanation:

In the above example, we have declared a float variable named "marks" and assigned it the value of 85.5. We have then used printf() function to display the string "My marks are " followed by the value of the variable "marks". The "%f" is a placeholder for floating-point values.

scanf() function: The syntax of scanf() function is as follows:

Here, "format string" is the string that specifies the format of the input, and the "&" sign before each variable is used to get the address of the variable.

Example 3:

Output:

Explanation:

In the above example, we have declared an integer variable named "age". We have then used printf() function to display the string "Enter your age: " to prompt the user to enter their age. The scanf() function is then used to read the value of age from the user. The "%d" is a placeholder for integer values.

printf() and scanf() are two important functions in C programming language. printf() is used to display output on the console, while scanf() is used to read input from the user. In this tutorial, we have learned how to use these functions with examples, output and explanations.