C Primer Plus reading notes Chapter III

Source: Internet
Author: User

The title of this chapter is data and C, and the main content is the description of the integer type and the floating-point type in the data type.

The first piece of code in this chapter

#include <stdio.h>int main (void) {    float weight;  /* User's weight */    float value;   /* Value of RH of equal Weight *    /printf ("is worth your weight in rhodium?\n");    printf ("Let's Check It out.\n");    printf ("Please enter your weight in pounds:");    /* Get input from user *    /scanf ("%f", &weight);    /* Assuming Rhodium is $770 per ounce, 14.5833 convert avoirdupois pounds into troy ounces */    value = 770 * weight * 14.5833;    printf ("Your weight in rhodium is worth $%.2f.\n", value);    printf ("You are easily worth that! If rhodium Prices drop.\n ");    printf ("Eat more to maintain your value.\n");    return 0;}

Focus on the scanf () function,%f means that scanf () reads a floating-point number from the keyboard, and &weight specifies that the input value is assigned to a variable named weight. The scanf () function uses the & symbol to indicate the position of the weight variable.

The focus of this chapter is on data and data types. Although the C language provides many data types, it can be divided into two series by storage: integer type and floating-point type.

The main difference is that floating-point notation is a number divided into fractional and exponential parts and stored separately.

Here are some of the areas to note about C data types:

1.int type

The C language provides multiple integer types. The main reason is that the various integer types in the C language provide different ranges of values, and whether the values can be signed or unsigned.

2. Other types

When passing a function parameter, C automatically converts the value of the short type to the int type. Because the int type is considered to be the most convenient and efficient type of integer that the computer handles.

3.char type

On a technical implementation, the char type is an integer type.

4._bool type

C99 introduced to represent a Boolean value. It is actually an integral type that requires only 1 bits to store.

5. Portable Type: Inttypes.h

An alias of an existing type. Provided by C99. For example, int16_t represents a 16-bit signed integer type. To use this feature, you need to include the Inttypes.h header file.

6.flaot, double, long double type

The float type must represent at least 6 significant digits. The value range is 10e-37 to 10e37. The system uses 32 bits to store a floating-point number: 8-bit index and symbol, 24-bit non-exponential part and symbol. Double and long double are more accurate than float. By default, the compiler treats floating-point constants as double types.

7. Complex and imaginary types

C99 Standard Support.

After-school exercises are all about the printing of printf () and various format specifiers. Not very difficult.

To be Continued ...

C Primer Plus reading notes Chapter III

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.