Showing posts with label General Input/Output Statement. Show all posts
Showing posts with label General Input/Output Statement. Show all posts

Tuesday, February 9, 2016

General Input/Output Statement

They cannot be used with other data type. What if you need to read a float or double value as input? C has functions for general input/output operations to handle this situation. These functions areprintf and scanfand they have following syntax.
  1. printf( "format", value_1, value_2, ...value_n);
  2. scanf("format", address_1, address_2, ...address_n);

Output Using printf

printf is used to perform generic output operation. The first parameter, 'format' is a string that specifies how the output needs to be formatted. Other parameters are optional for printf. The 'format' string can contain format specifiers (conversion characters) to specify how the other parameters needs to be handled. Each data type has an associated format specifier. For example, to print an integer value, you can use '%d' as format specifier, '%f' can be used for float etc. With the format specifiers, the printf statement would look like
  1. int value = 10;
  2. printf( "%d", value);
If the first argument doesn't have any conversion characters, it will be written as it is to the standard output.