c - I don't understand one dimensional array handling with function passing -


I have an array whose record is a name [10], whose type is a table structure, {int, Int, long, long, four}

I have a function that I want to pass the address of this array, which is called in the loop:

< For pre (I = 0; i & lt; 10; i ++) {// Internal solution will be * (record + I) will receive an address function (record [i]); }

I am confused as to why I am not working. I know that it is related to the basics.

To start working with

  (i = 0; i <10; i ++) {// Then why should I address this address Pass on here (& amp; [i]); }  

* (record + i) is not in it Fact is an address record an address, and is such a (record + i) , but * (record + i) that The value stored on (record + i) is the address represented by Therefore, calling the function (record [i]) is the function (* (record + i)) , which is the function of the value array element, one Not an indicator.

Syntax & amp; Record [i] is not detecting an address It is detecting the record [i] , which is an object that has high priority for braces compared to ampersands, Code> and [i] record (record [i]) . You can think of it as an extension of and (* (record + i)) and then (record + i) can be simplified.

Update: To resolve your question with the comment, if you refer to the name of the array by itself, then an array "decays" in an indicator. If you add square brackets [] , you will get an value from within the array. Therefore, for your example, say that you have an array of structures:

  struct A {... char abc [10]; ...} records [10];  

Then, you will have:

  • records [i] - an object type struct A From Record ARA
  • Record [i] .abc - ABC array is a special
  • Record & Amp; Record [ii]. ABC [0] - A method of making an indicator in the string

notation records [i] -> gt; ABC that you have used in your comment can not be used, because records [i] is an object and not an indicator.

Update 2: In relation to your second comment, the same rules as described above apply, whether you nest the array within the structure (and whether you use that structure Directly or through an indicator). Using an array using the array name [index] notation you will give an item with the array. Using an array using the arrayname signaling (i.e., using the array name) will give you an indicator for the first element in the array. If you need more information about this incident, here are some links that explain the arrays and the way their names pointers can be decayed:


  • Comments