Three ways to create symbolic constants in C language; printf () and scanf () functions

Source: Internet
Author: User

1, #indefine the macro definition of pi 3.1415926 form

2, const int months=12; This causes MONTHS to become a read-only value.

3. Enum Enum type



4. The printf () and scanf () functions enable us to communicate with the program, they are called input/output functions, (I/O functions)



5, string, floating-point output type and Description: Instance program:

 #include <stdio.h> #define  BLURB  "authentic imitation!" Macro definition Mode Int main (void) { const double rent=3852.99;//Const method-defined constants/* Following are the use of some format flags */printf ("%x  %x  % #X \ n ", 31,31,31); the hexadecimal representation of//%X31 indicates that the hexadecimal representation of 31 is 1F; use # to make the output start with 0x 0x1f;printf (" **%d**%d**%d**\ n ", 42,42,-42);p rintf (" **%5d**%5.3d**%05.3d**\n ", 6,6,6,6);/* The case in the string is as follows: */printf ("/%2s/\n ", BLURB);//Default output printf ("/ %24s/\n ", BLURB);//create 24bit space in memory, the characters are not enough to fill with blanks from the left. printf ("/%24.5s/\n", BLURB), or//a total of 24 space, but the precision required to retain 5 bits, preceded by a space. printf ("/%-24.5s/\n", BLURB);//Ibid., just-indicates that left alignment is required. /* Following is a combination of some floating-point numbers */printf ("*%f*\n", RENT);p rintf ("*%e*\n", RENT);p rintf ("*%4.2f*\n", RENT);p rintf ("*%3.1f*\n", RENT); /By the output is not difficult to see, 3.1f represents the output should be a total of three bits, 1 for precision, so there is rounding, the original number of more than 3, automatic expansion. printf ("*%10.3f*\n", RENT);//output should be a total of 10, not enough words from the left to start the space, after the decimal point there are 3 digits, the number of decimals is not enough to use 0-fill printf ("*%10.3e*\n", RENT);p rintf ("*%+4.2f* \ n ", RENT);p rintf (" *%010.2f*\n ", RENT);//represents 10 bits in 0 and 2 for precision. return 0;} 

Results: 650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9D/32/wKiom1l7IyvjunZjAAMQvGxqde4055.png "title=" Untitled. png "alt=" Wkiom1l7iyvjunzjaamqvgxqde4055.png "/>



Three ways to create symbolic constants in C language; printf () and scanf () functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.