scanf in c


                                           
                                                                              
In this blog
scanf explanation


scanf explanation

scanf is used in taking input in user , it returns the no of values that are readed form user.

syntax :
                        scanf("control string", arg1 .... , argn);

control string:
                              it means type of data that is to be read form user. it is give by
                                      
                                                 %[*][width][modifier]type

argq....,argn:   
                          these are addresses of variables , which can be given by writing (  &var ).

(all the things specified in the square brackets are optional)



*
it is used to suppress the input ( input is taken form user but  would not store it in variable)

eg : 
scanf("%*d",&a) //  a is of int type 

input                                                                                                             output

123                                                                                                             garbage value  or                                                                                                                          no value if  we                                                                                                                           tried to print a



width

it is used in case of scanning string ,by specifying , it will limit the no of character

eg : 
scanf("%3s",a) //  a is character array 

input                                                                                                             output

HelloWorld                                                                                                   Hel



 modifier

length modifier are nothing but the modifier used with the basic data type 

 length their use
  h when variable is of type short or unsigned shot
 l when variable is of type long or unsigned long
 L when variable is of type long double

eg for long double:
  
printf("%Lf",a); 

input:                                                                                                     output:                                                                      
a=345.34                                                                                               345.340000


(type is any valid data type in c)

(leave the comment down below if you have a doubt or suggestions ,thnks🙂)

No comments:

Post a Comment

Contact Form

Name

Email *

Message *