Printing Variables with printf function - C Language Basics

C examples for Language Basics:Hello World

Introduction

printf function can print values and variables to the console window.

#include <stdio.h>

int main() {
  int x = 5;
  printf("x is %d and 2+3 is %d", x, 2+3);
}

The %d specifier displays an integer of the char, short or int type.

Other commonly used format specifiers are seen in the following table.

Specifier Output
%d or %i char, short, or int
%ccharacter
%sstring of characters
%ffloat or double
%Lf long double
%ld long int
%lld long long int
%uunsigned char, short or int
%lu unsigned long int
%llu unsigned long long int
%ppointer address

Related Tutorials