Basic input and output function in C.

Hello coders! Welcome back.

Today will look into how to feed input to the code and how to get output from the compiler. We will look into the syntax of input and output instructions.

Let's begin with the output function.

The syntax for output function is given as-








Here printf means to print the data in the specified memory location after formating the data (format data means converting data into appropriate data type).

Let's discuss the examples mentioned above.
In the first example, %d represent the format specifier. This means the value present in x is replaced with the first %d symbol and the value present in y is replaced with the second %d symbol.
%d  denotes an integer. will discuss different format specifiers into our next blog.

In the second example, code_with_me18 is printed as it is. Since it is a pure text form.

Next will discuss the Input function.

The syntax for input function is given as-







scanf statement is used to read data from standard input device that is keyboard.

In the above example scanf takes integer data type as input and store it in X and Y location.

What is significance of & symbol?
We know that scanf is going read the data and store it in memory location. To get the memory location we use & symbol.
Complier reads it as 'address-of ' operator.
For example -
&x is nothing but address of x.
&y is nothing but address of y.
With it's help the data is stored in correct location.

A format specifier should always begin with the % symbol.
And the address list should always begin with the & symbol.




💡PRO TIP:- scanf always accepts the address of variables as arguments. If it is not mentioned it shoots an error message.  

I hope so, you got a clear idea about input and output function and their syntax. If any doubts in your mind drop a comment. Always ready to clear them. 

Happy learning! 

Comments

Popular post