TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C Tutorials

C printf Function

Overview

The C printf function is a standard library function. The Standard Input/Output Library contains functions for formatted data transfer in and out of the C program. The two such functions are as follows:

  • printf (print formatted) function
  • scanf (scan formatted) function

The data printing and reading functions are defined as standard functions which are part of
the language specification but are not part of the C Language itself. The functions are defined in the system header file stdio.h

C printf Function

The printf function formats and displays the arguments on the standard output. By default, it prints the output to the terminal(the standard output device)

The printf() function prints output to the standard output stream i.e stdout, according to format and other arguments passed to printf().

Syntax

The general syntax of the printf function is as below:

printf(format, arg1,arg2,arg3,…);

The string format consists of two types of items:

  • Characters that will be printed to the screen
  • conversion specifiers that define how the arguments are displayed.

Examples

Print String

In this example, we will print the string literal to the output screen using the print() function. A string literal is a combination of characters like letters, digits, and other special characters enclosed in double quotation marks. For example, “My name is, John!”

The print() function call to print the string literal “Hello, World!” is shown below:

printf(“Hello, World! \n”);

 

C printf Function

Note that the printf function will not print the new line. We can achieve this with \n character sequence. The \n is the new line character. This sequence advances the terminal to the left margin of the next line.

Print Number

In this example, we will print the number along with string information. The argument number is an integer variable. The format specification %d is for printing in decimal notation.

For example:

printf(“The total sum is %d”,number);

Related Posts

C Language Characteristics

C Tutorials /

C Language Characteristics

C Source Code .c File

C Tutorials /

C Program Files & Formats

GNU Compiler Collection GCC

C Tutorials /

C Compilers

C Pointers

C Tutorials /

C Pointers

C Tutorials /

C Two-Dimensional Arrays

‹ C Programming Environment› C Variable Initialization

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version