[Study Notes] [C Language] memory Analysis of variables, learning notes C language Variables

Source: Internet
Author: User

[Study Notes] [C Language] memory Analysis of variables, learning notes C language Variables

The memory in the computer isBytesThe unit of storage space. Each byte in the memory has a unique ID, which is calledAddress. As if the hotel is based on the room, each room has a unique room number, and we can find the corresponding room according to the room number.

1. Storage of Variables

1> the number of bytes occupied is related to the type and the compiler environment.

Void putBinary (int n) {int bits = sizeof (n) * 8; while (bits --> 0) {printf ("% d", n> bits & 1 ); if (bits % 4 = 0) printf ("");} printf ("\ n ");}

2. Storage of negative numbers in memory

1 int main () 2 {3 int B =-10; 4 return 0; 5}

The value of an integer variable is-10 in row 3rd. -10. How can I store the data in the memory? In fact, any value is stored in the memory as a complement.

  • The positive complement is the same as the original code. For example, the source code and the complement code of 9 are both 1001
  • The complement code of a negative number is equal to the original code of a positive number and then + 1. (Inversion means 0 to 1, 1 to 0)

The-10 complement code calculation process is as follows:

1> first calculate the binary form of 10: 0000 0000 0000 0000 0000 0000 0000 1010

2> decimal 10 binary: 1111 1111 1111 1111 1111 1111 1111 0101

3> result of reverse retrieval + 1111 1111 1111 1111 1111 1111 0110

Therefore, the binary format of integer-10 in the memory is: 1111 1111 1111 1111 1111 1111 1111 0110

3. Value Range

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.