Linux memory ~~~~ Set ~~

Source: Internet
Author: User

SourceProgramAs follows:
# Include <stdio. h>/* c99 standard */
Int main (void)
{
Int Zippo [4] [2] = {2, 4}, {6, 8}, {1, 3}, {5, 7 }}

Printf ("Zippo = % P, zippo + 1 = % P \ n ",
Zippo, zippo + 1 );
Printf ("* (Zippo + 2) + 1) = % d \ n", * (Zippo + 2) + 1 ));

Return 0;
}
The system output is as follows:
Zippo = ox0064fd38, zippo + 1 = ox0064fd40
* (Zippo + 2) + 1) = 3

Int type occupies 4 bytes, so from Zippo to Zippo + 1, the address stores the {2, 4} integers.
8 bytes in total. The memory address is also from
0x0064fd38
0x0064fd39
0x0064fd3a
0x0064fd3b
0x0064fd3c
0x0064fd3d
0x0064fd3e
0x0064fd3f
Ox0064fd40
That is, each address represents a byte, 8 bits.
Does this mean that the minimum storage is 8 bits?
If so, looking at a previous Huawei interview question, it is generally to store a piece of data and request its minimum storage space. one of them is gender. The minimum storage space is 1 bit (). However, 1 bit space cannot be allocated to this project based on memory space allocation, the minimum value is 1 byte, so it will waste 7 bits, but the fact is only like this (if the question above is correct). Does this mean that the actual answer is 1 byte, not 1 bit, huawei's answer 1 bit is only a theoretical value? Cannot I actually allocate 1 bit space for it? Is that true?
What's more, the _ bool type introduced in the c99 standard, How much memory is occupied? Is it 1 byte?

========================================================== ========================================

A> Please use C language to write a program to test memory from address 0x0000 ~ 0 xFFFF
By the following methods:

1> Please write data 0xab to each byte, then read it back and compare the result. if all memory location test pass, then show "memory data test pass 'on the screen. if any memory location finds error, then show "memory data test fail" on screen.

2> Please use the address value as the data and write into each memory location and read it back to compare the result. for example, write the address value 0x0000 to memory location 0x0000, and value 0x0001 to location0x0002 ,... Till 0 xfffe

1. (The following program cannot be used for Windows ):

# Include <stdio. h>

Void main ()
{
Unsigned int I = 0;
Unsigned char * p = 0x0000;
For (I = 0; I <0x10000; I ++)
{
* P = 0xab;
If (0xab! = * P) break;
P ++;
}
If (0x10000! = I)
Printf ("memory data test pass \ n ");
Else
Printf ("memory data test fail \ n ");
Return;
}

2. (The following program cannot be used for Windows ):

# Include <stdio. h>

Void main ()
{
Int I = 0;
Unsigned char * p = 0x0000;
For (I = 0; I <0x8000; I ++)
{
* (Unsigned short *) P = I;
If (I! = * (Unsigned short *) P) break;
P + = 2;/* return lengxuehou: the original question address is calculated in bytes, and one 16-bit address value requires one short value to be stored, so P increments by 2 at a time, and I is to count the total number of short. You can check the last sample of the original question */
}
If (0x8000! = I)
Printf ("memory data test pass \ n ");
Else
Printf ("memory data test fail \ n ");
Return;
}

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.