Thursday, 15 May 2014

c - checking my understanding of pointers/structures and arrays -


All I am just trying to understand some key concepts, and have done my own research but there are some questions and really appreciate it if someone can see if they are right. I am making a review for a test, and our professor told us to understand myself ... so I did and here it went :)

1: Pointer Announce the pointer to keep the address of an element in an array with 10 elements, which are called

  int pointed [10] = {}; Int * thePointer = & amp; Appointed [1];   

Need help with this one ...

2: Write a function that will accept the address of an array and elements in an array Use the information to begin the number and the element of zero

  for the zero array function (int * array, int element) (x = 0; x & Lt; element; x ++); {Array [x] = 0; 3: Create a structure that represents the following structure:   

- 2 fields that hold every 4 BT BCD points Together, they keep the current rotation count (I call them CRC1 and CRC2): speed of 2 beats: 4 Beats Fault Statement: 3 Beats Structure Control Name Motor < Pre> Structure Control Mounter {Unsigned four CRC 1: 4; Unsigned four CRC 2: 4; Unsigned int motor direction: 2; Unsigned int speed: 4; Unsigned error: 3; };

- Type a type to name this new data type: statusDrive_t

  typedef control motor statusDRIVE_T;   

- Make a Merced Drive of named structures to position each 6 drives

  statusDrive_t marsDrive [5] = {< / Code>  

Start each field of the first element of the array with the maximum value

  Mercredrive [0] .CRC1 = 15; Mercredri [0] .RCC 2 = 15;    

1 looks fine, but you & amp; / Code> operator bus:

  int * thePointer = pointed;   

will work because the arrays will get decayed in pointers.

2 Write a function that will accept the address of an array and the number of elements in the array takes your function only one int Was asking, it is not close to it. This question is trying to give you a reference that information passing through the array in the function is lost as the number of elements in the array.

I'm pretty sure they were looking for something else:

  Zero array function (int * arr, int element) // You can (int arr [], ... as well as {int (ii = 0; i & lt; element; i ++) arr [i] = 0;} int main (zero) {int i [4]; arrayfunction (I, 4);   

3 Your typed is incorrect, it should be:

  typedef struct control motor position Dreive_t;   

The syntax is:

  typedef  gt; new name to name it;   

And in this case this type is < The code> struct controlMotor

array is also declared incorrectly. int marsdrive [6] one of the int s The array creates the array you want to type before, so in this case since you have just typed that fancy new one:

  statusDrive_t marsdrive [6];  < / Pre> 

For an array composition controlometer of 6 (numbered 0 to 5) and the last part of 3: start each field of the first element of R. ray with maximum value You need to start the area of ​​the first element. It has been done by:

  marsDrive [0] .CRC1 = ... marsDrive [0] .CRC2 = ...   

Increase the value in [] You are moving away from the first element. You can find the maximum "maximum" size by the number of bits, for example CRC is 1 4 Beats, that means You have a maximum of 1111 2 which is 15 10

No comments:

Post a Comment