Printf function
1. Understand that the printf function in C is kept in the cstdio library. You may need to include the stdio.h header file to use this function.
2. Learn the syntax of printf. The complete syntax is int printf ( const char * format, ... ). This function takes character pointers as arguments and returns the number of characters written if the command is successful. Otherwise, printf returns a negative number.
3. Know that the format may contain format tags using the following prototype: %[flags][width][.precision][length]specifier. Fields that are enclosed in brackets are optional. Note that the specifier is the only required component of the tag. The specifier must be one of the following: c (character); d or i (signed decimal integer);
e or E (Scientific notation using e or E); f (decimal floating point); g or G (use the shorter of %e/%E or %f); o (signed octal integer); s (character string); u (unsigned decimal integer); x (unsigned hexadecimal integer using lowercase letters); X (unsigned hexadecimal integer using uppercase letters); p (pointer); n (nothing printed)
Scanf Function
1. Understand that the scanf function is kept in the cstdio library. You may need to include the stdio.h header file to use this function.
2. Learn the syntax. The complete syntax is int scanf ( const char * format, ... ). This function returns the number of items read. If scanf fails before any data is read, an EOF will be returned.
3. Know that the format may contain format specifiers using the following prototype: %[*][width][modifiers]type. Fields that are enclosed in brackets are optional. Note that the type is the only required component of the tag. The type must be one of the following: c (single character); d (decimal integer); e,E,f,g,G (decimal floating point); o (octal integer); s (character string); u (unsigned decimal integer); x,X (hexadecimal integer).
4. Note that a character string (s) type will read characters until a blank, newline or tab character is encountered.
Related Videos