Thursday, 26 June 2014

Understanding scanf()

c and c++ tutorials // online learning spot
scanf(<field 1>,<field 2>) has 2 fields or 2 sections or we can say 2 parameters. These parameters are seperated by each other using a comma. It is compulsory to give 1st parameter and second parameter is optional ( we saw in previous example scanf("%c") ).

Now question arises what is this parameter?
To understand the word "parameter" let us have an example :
To calculate volume of a cube we needed its length breadth and height. These are called parameters of cube, that are needed to calculate its volume.
Similarly scanf() needed 1 compulsory parameter and 1 is optional.

What are types of scanf's parameters?
1st parameter is a string that contains type specifier of input and 2nd is a list of variables, these variables will store those input values.

What are Type Specifier?
They are used to identify the type of incoming data stream.
Some basic type specifier
  • character input : %c
  • integer input : %d
  • real number input : %f
we will later understand them more, now take a look on variables in next lesson.

<<Back        Next>>



No comments:

Post a Comment