The o, x, X, #, g and G conversion specifiers for floating-point used in printf() C function
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: The o, x, X, #, g and G specifiers for floating-point used in printf() C function
To show: How to use the o, x, X, #, g and G for floating-point representation in C programming
// The o, x, X, and any floating-point specifier
#include <stdio.h>
int main()
{
int c = 1427;
float p = 1427.0;
printf("o, x, X, and any floating-point specifiers\n");
printf("Compare the output with the source code\n");
printf("-----------------------------------------\n\n");
printf("%#o\n", c);
printf("%#x\n", c);
printf("%#X\n", c);
printf("\n%#g\n", p);
printf("%#G\n", p);
return 0;
}
Output example:
o, x, X, and any floating-point specifiers
Compare the output with the source code
-----------------------------------------
02623
0x593
0X593
1427.00
1427.00
Press any key to continue . . .