Format Specifiers in C Language

Format specifiers in C Language

Format specifiers are used to specify the type of data to be printed on the output screen. In C language, a format specifier starts with % and ends with a conversion character.

Basic Format Specifiers
Format Specifier Output Format
%d Integer (decimal)
%i Integer (decimal, octal, or hexadecimal)
%f Floating-point number (decimal notation)
%e or %E Floating-point number (scientific notation)
%c Single character
%s String of characters
%p Pointer address

Example:

int a=10;

float b=20.5;

printf(“Integer value is %d and Float value is %f”,a,b);

Output:

Integer value is 10 and Float value is 20.5

Format specifiers example

// Create variables
int val = 15;            // Integer (whole number)
float val2 = 5.99;   // Floating point number
char name = ‘D’;       // Character

// Print variables
printf(“%d\n”, val);    // %d is a integer format specifier & \n is for new line on the out put console
printf(“%f\n”, val1);    // %f is a float format specifier
printf(“%c\n”, name);    // %c is a character format specifier

 

Declare Multiple Variables in C Language

int num1, num2, num3;

float num4, num5, num6;

char ch1, ch2, ch3;

Declare Multiple Variables in C Language

int num1, num2, num3;

float num4, num5, num6;

char ch1, ch2, ch3;

 

int x = 5, y = 6, z = 50;
printf(“%d”, x + y + z);

int x, y, z;
x = y = z = 50;
printf(“%d”, x + y + z);

Leave a Reply

Your email address will not be published. Required fields are marked *

https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
About
Products
Subscribe

If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

    Applauz

    As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

    Subscribe

    If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

      Applauz

      As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

      Copyright by BOLD THEMES. All rights reserved.