C Language Learning (3) sizeof function, memory address, array
SizeofIt can be used to calculate the memory bytes occupied by a variable, a constant, or a data type.
Sizeof (10 );
Char c = 'a ';
Sizeof (c );
Sizeof (float );
Address
1. Memory in the computer is the unit of storage space in bytes. Each byte in the memory has a unique ID, which is called an address.
Every program and data stored in the memory has an address, that is, a function also has its own memory address.
2. When a variable is defined, the system allocates a storage unit with a unique address to store the variable. For example:
Char a = 'a'; // the ASCII value of A is 65
Int B [] = {66,33 };
In the 16-bit compiler environment, the system allocates 1-byte and 2-byte storage units for a and B respectively. The address of the first byte of the variable storage unit is the address of the variable.
It can be seen that the address of variable a is ffc3; the address of variable B is ffc1. Binary data is stored in the memory.
One-dimensional array <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Release + release/dfpw/release + release/w/release + release/J0tTKx8r91 + nL + dPQ1KrL2LXEs/release/ydLUysfHsMPmsr + signature + signature/Signature + CmludCBhWzNdOzwvcD4KPHA + signature/dfpw/thILT6se2x5MG/Signature + signature/dfp1/Signature + signature + nD + signature/ bj21KrL2LXE0rvOrMr91 + k8L3A + CjxwPgo8YnI + cda-vcd4kpha + CtTaxNq05tbQtcS05rSix + m/Signature =" http://www.2cto.com/uploadfile/Collfiles/20141204/2014120408592174.png "Width =" 400 "height =" 150 "alt =" \ ">
(Note: a [0] And a [1] are also arrays, which are one-dimensional arrays, and a [0] And a [1] are array names, therefore, a [0] And a [1] represent the addresses of this one-dimensional array)
1> the address of array a is ffc1, and the address of array a [0] Is ffc1, that is, a = a [0];
2> the address of element a [0] [0] Is ffc1, so the address of array a [0] is the same as that of element a [0] [0, that is, a [0] = & a [0] [0];
3> the final conclusion is as follows: a = a [0] = & a [0] [0], and so on. a [1] = & a [1] [0] can be obtained.
Printf ("% p \ n % p", a, a [0], & a [0] [0]);
Two-dimensional array Initialization
* Initialize by row
Int a [2] [3] = {2, 2, 3}, {3, 4, 5 }};
* Initialize in the storage Order (store 1st rows first and then 2nd rows)
Int a [2] [3] = {2, 2, 3, 4, 5 };
* Initialize some elements.
Int a [2] [3] ={{ 2}, {3, 4 }};
Int B [3] [3] = {{},{,, 2 },{, 3 }};
* If only some elements are initialized, the number of rows can be omitted, but the number of Columns cannot be omitted.
Int a [] [3] = {1, 2, 3, 4, 5, 6 };
Int a [] [3] = {1, 2, 3}, {3, 5 },{}};
Why can't I just omit the number of columns? Because int a [2] [] = {1, 2, 3, 4, 5, 6} cannot determine the row where the element is located.