[C ++ Primer] Chapter 3 Study Notes (processing data)

Source: Internet
Author: User
Tags float double

Process Data
I. Classification

Basic Type + Composite Type
Basic types include integer and floating point

Composite types include: structure (struct)

Integer Classification
Integer: char short int long and unsigned
Float: float double long double
Boolean: boole is sometimes an integer.
Ii. Integer explanation

1. Expression

Short = short int
Long = long int
2. Function usage

Sizeof () // Length byte of the returned type
Sizeof variable // parentheses can be omitted

3. Use of infinite values

To obtain the extreme values of each type. You can add
# Include "limits. h"
INT_MAX, INT_MIN // represents the maximum and minimum integer values, respectively.

4. Differences between the number of unsigned characters and the number of signed characters
-128-127 0-255 short type; the highest bit of the unsigned number can be used as a value

5. Extreme Value addition and subtraction:
1> signed number: int max = INT_MAX;
Unsigned number: unsigned int un_max = INT_MAX;
Max ++
Un_max ++


Max =-2 ^ 31
Un_max = 2 ^ 32 + 1

2> signed number: short sam = 0;
Unsigned number: unsigned short un_sam = 0;
Sam --;
Un_sam --;

Sam =-1;
Un_sam = 255;

6, long; unsigned long: at least 64-bit
7. optimization considerations: If there are no large integers, use short (if possible)
Char can also
8, int a = 42; // decimal
Int B = 042; // hex
Int c = 0x42; // hexadecimal octal

 

Cout <"a =" <a <endl; // output in decimal format

Cout <"B =" <B <endl; // output in octal format
Cout Cout <"c =" <c <endl; // hexadecimal output
Cout <oct;

9. namespace
If cout is used like this
Std: cout <
Std: endl
Std: hex
Std: oct
The preceding keywords (cout, endl, hex, oct; such as int cout;) can be used as variable names.

Std: cout. put ('D'); // output function
10, const read-only

Const int;
A = 9;
// This is incorrect. After definition, the value cannot be changed.
Const is better than define
1> explicitly specify the type
2> you can use the scope to limit the range of variables defined by const to a file or function.
3. Floating Point Number
1. float 32-bit valid digits
Double 64-bit
Long double 80 96 128
Float can only represent the first six digits of a value

2. Forced type conversion does not change the value of the variable itself.

Int B = (int)
It does not change the value of a. It only changes the value of B.

From the column of ODA

Related Article

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.