The array data type in C -
by reading details pointer , arrays in c got little confused. @ 1 hand array can seen data type. @ other hand array tends unmodifiable lvalue. imagine compiler replacing arrays identifier constant address , expression calculating position given index @ runtime.
myarray[3] -(compiler)-> ae8349f + 3 * sizeof(<type>)
when speaking array data type, mean? hope can me clarify confused understanding of array , how treated compiler.
when speaking array data type, mean?
a data type set of data values having predefined characteristics. examples of data types are: integer, floating point unit number, character, string, , pointer
an array group of memory locations related fact have same name , same type.
if wondering why array not modifiable best explanation have ever read is;
c didn't spring formed mind of dennis ritchie; derived earlier language known b (which derived bcpl).1 b "typeless" language; didn't have different types integers, floats, text, records, etc. instead, fixed length word or "cell" (essentially unsigned integer). memory treated linear array of cells. when allocated array in b, such as
auto v[10];
the compiler allocated 11 cells; 10 contiguous cells array itself, plus cell bound v containing location of first cell:
+----+ v: | | -----+ +----+ | ... | +----+ | | | <----+ +----+ | | +----+ | | +----+ | | +----+ ...
when ritchie adding struct
types c, realized arrangement causing him problems. example, wanted create struct type represent entry in file or directory table:
struct { int inumber; char name[14]; };
he wanted structure not describe entry in abstract manner, represent bits in actual file table entry, didn't have cell or word store location of first element in array. got rid of - instead of setting aside separate location store address of first element, wrote c such address of first element computed when array expression evaluated.
this why can't like
int a[n], b[n]; = b;
because both a
, b
evaluate pointer values in context; it's equivalent writing 3 = 4
. there's nothing in memory stores address of first element in array; compiler computes during translation phase.
1. taken paper the development of c language
for more detail may read answer.
edit: more clarity; difference between modifiable l-value, non-modifiable l-value & r-value (in short);
the difference among these kinds of expressions this:
- a modifiable l-value addressable (can operand of unary &) , assignable (can left operand of =).
- a non-modifiable l-value addressable, not assignable.
- an r-value neither addressable nor assignable.
Comments
Post a Comment