Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

3.4. Quick Explanation of printf()

You may have noticed two characters near the end of our printf() statements \n. These don't get displayed to the screen, they are the notation printf() uses to represent "newline". '\' is the c escape character when it is encountered within quotes the following character usually has a special meaning. Another example is \t which is used to represent a TAB.

Another special character that printf() looks out for is '%', this tells it to look at the next few characters and be ready to replace them with the value of a variable. %d is the character sequence that represents a variable of type int to be displayed using the decimal counting system (0 .. 9). For every %d in the format string you must tell printf() what variable you want it replaced with. Here's some more use of printf() in code:

Example 3-4. more_printf.c

int
main()
{
  int one = 1;
  int two = 2;
  int three = 4;  /* the values are unimportant here */

  printf( "one ==\t%d\ntwo ==\t%d\nthree ==\t%d\n", one, two, three );

  return 0;
}
     

 
 
  Published under the terms of the GNU General Public License Design by Interspire