GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Placement Papers  >  CSC

 Print  |  
Question:  char str[10];
int i;
for(i=0;i<=9;i++)
scanf("%s",&str[i]);
for(i=0;i<=9;i++)
printf("%c",str[i]);

What will be the difference if we use %c instead of %s in scanf, give reason also




July 07, 2008 05:53:12 #1
 Ishan Sharma   Member Since: July 2008    Total Comments: 1 

RE: char str[10];int i;for(i=0;i
 

With %s it will take 9 name or words but prints only starting alphabets...and with %c it will take characters and prints 9 characters which have entered....

for eg:-

with %s it can take hello,going,sitting etc till 9 words but prints h,g,s i.e starting letter

with %c it will take hello and going as characters i.e it will consider each letter of hello and going as a independent unit and prints hellogoing as sitting will be out of it memory size

     

 

Back To Question