Data Types of constants and variables in c ++

Source: Internet
Author: User

Data Types of constants and variables in c ++

In c ++, how do I classify constants?

1. Integer constants, All integers. An integer is divided into four bytes. How many binary digits do one byte occupy? 8 binary bits, and an integer variable occupies 32 binary bits (the storage space opened in the memory)

2. Decimal constant, all decimals.

3. boolean constants with only two values: true and false.

4. A character constant, a letter or number, identified''

5. A String constant. One or more characters are identified.

6. null constant. Only one value is null, which indicates null.

A constant is also called a global constant. All functions can be called unless written in a function. All constant statements must use uppercase letters and all letters in uppercase.

What is a variable?

Variable concept:

(1) A storage area in the memory

(2) The region has its own name (variable name) and data type. How to name variables? The identifier. In c ++, the identifier can only contain letters, numbers, and underscores, and cannot start with a number. The identifiers in java are letters, numbers, underscores, and $, and cannot start with a number.

(3) data in the region can be continuously changed within the data type.

What are the format specifications used by variables?

The first method, for example: byte B = 3; // What should I pay attention to when naming? The letters of the first word are lowercase, the first letter of the second word is capital, and the first letter of the third word is capital. This is called a hump. The first word is used to start a class name.

C ++ and java are both sensitive and case sensitive.

Uppercase letters, Variable_Demo $ Byte

The second method, for example:

Char characterOfThisNumber, c2;
CharacterOfThisNumber = '3 ';
C2 = 'a ';

What is the significance of a variable? What is the purpose?

(1) reusable

(2) constantly changing values

What data types does Java have? How many?

 

How many binary digits do two short int short integer bytes occupy? 16 binary BITs, which can represent numbers from-2 ^ 15 ~ 2 ^ 15-1

What are the four bytes of an int integer in binary format? 32 binary BITs, which can represent numbers ranging from-2 ^ 31 ~ 2 ^ 31-1

Long int long integer 8 bytes 64 binary bits, can represent the number from-2 ^ 63 ~ 2 ^ 63-1

Double precision 8 bytes 64 binary bits, can represent the number from-2 ^ 63 ~ 2 ^ 63-1

How many binary BITs do float contain 4-byte and 4-byte? 32 binary BITs, which can represent numbers ranging from-2 ^ 31 ~ 2 ^ 31-1

Boolean has only two values: true and false.

How does the char character type express''

How does string represent ""

Exercise Question 1:

Output a long integer variable of 123456789012345

Long l = 123456789012345;

Exercise Question 2:

Returns a single-precision decimal constant of 2.4.

Float f = 2.4;

Exercise Question 3:

Outputs A boolean variable.

Boolean B = true; bool

B = false;

Exercise Question 4:

Forced type conversion

Double to float

Byte B = 3; // corresponds to a class in Java, Byte

B = B + 200;

B = (byte) (B + 200); // Why is the output result negative? Integer 203, which of the following memory bytes? 4 bytes 32 bits, and the converted byte occupies 16 bits in the memory,

Exercise question 5:

Output a balanced addition calculation.

System. out. println = sop

Sop ('A' + 1 );

System. out. println (char) ('A' + 1 ));

System. out. println (char) ('you' + 1 ));

Cout <

Exercise 6:

Int also corresponds to a class, Integer

Demonstrate the Overflow Effect of Variables

Int I = Integer. MAX_VALUE + 1;

Exercise 7:

Arithmetic Operator + -*/

X = x/1000*1000;

Cout

Sop (x );

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.