For each of the following pairs of scanf format strings ,indicate whether or not
ID: 3616579 • Letter: F
Question
For each of the following pairs of scanf format strings ,indicate whether or not the two strings are equivalent . If they 're not , show how they can be distinguished . (a) "%d" versus " %" (b) "%d-%d-%d" versus "%d -%d -%d" (c) "%f" versus "%f " (d) "%f,%f" versus "%f, %f" For each of the following pairs of scanf format strings ,indicate whether or not the two strings are equivalent . If they 're not , show how they can be distinguished . (a) "%d" versus " %" (b) "%d-%d-%d" versus "%d -%d -%d" (c) "%f" versus "%f " (d) "%f,%f" versus "%f, %f"Explanation / Answer
a) Clearly they are not equivalent Reason: %d takes integer values in scanf while %does not know what values it will take b) They both are different. For the first one you should give the input ase.g.: 12-20-30 but you cannot give as 12 - 20 - 30 (spaces inbetween_ but for the second one you can give the inputeither as 12-20-20 or 12 - 20 - 30 (both wil work wihtout anyerrors) c) Both are different... For the first one...you can given input eitheras e.g. 12.5 or "12.5 " (i.e. space after 12.5) The second one always waits for another input(you should give 12.5 space and another value like 1..then only itwill read 12.5) d) Both are the same They will take input either as 12.5, 13.4 or12.5,13.4 (no space between both numbers)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.