printf() and scanf() function § printf() and scanf() function are used as basic I/O function. § printf syntax: • printf(string, expression 1, expression 2, ……) § No limit on number of value can be that can be printed § Format string may contain ordinary character and conversion specification begin with % § Conversion specifier specifies compiler to convert into specific format. § Though compiler doesn’t check the conversion specification number should match.
Why following printf() is wrong § printf(“%d %d”, i); § printf(“ %d”, i, j); § int i; float x; printf(“%f %dn”, i, x);
Conversion Specifier § d deimal § e floating point is exponential § f Display floating point number § c character § s string § %. 1 f display float value with one digit decimal § %4 d display with space in front (Right justification) § %-4 d display with space in back (Left Justification)
Example
Escape Sequence § Non printing character having special meaning § Start with § Some common escape sequence are
The scanf() function § Takes input from user, § Syntax • scanf(“string ”, &variable, ………. . ) § Never FORGET to use & before variable § Confusing printf() and scanf() …