User Tools

Site Tools


notes:data:fall2023:projects:ttb0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:data:fall2023:projects:ttb0 [2023/09/14 02:53] – [ACCESSING WITH POINTER ARITHMETIC] cfoster8notes:data:fall2023:projects:ttb0 [2023/09/14 02:58] (current) – [MALLOC’ED ARRAY] cfoster8
Line 76: Line 76:
          
 =====MALLOC’ED ARRAY===== =====MALLOC’ED ARRAY=====
 +The array exists as a linear allocation of memory, and any particular value in the array can be accessed by adding the value of that location to the pointer when calling it
  
-To access the specific parts of your array you need to use (*(ptr)). +Example: 
-The ptr is the pointer and it can be added to (*(ptr+n)).. If you want to use a part of the structure you will need to put the name of it at the end of (*(ptr)).(varible). You can use an int to add to ptr. The ptr starts with zero so use one more number than you want. +    (*(b_arr + 0)).x = 20; 
 +would make the first x value of the array 20 and 
 +    (*(b_arr 1)).x = 30; 
 +would make the second x value of the array 30, and so on
 ====ACCESSING WITH POINTER ARITHMETIC==== ====ACCESSING WITH POINTER ARITHMETIC====
 Pointers to structs can be accessed the same way a class can, like so Pointers to structs can be accessed the same way a class can, like so
notes/data/fall2023/projects/ttb0.1694660006.txt.gz · Last modified: 2023/09/14 02:53 by cfoster8