Array or not?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alexanderzats

    Array or not?

    I stumbled across strange bit of code (probably it's my lack of c syntax):
    argument
    Code:
    uint8* Y_dst1
    is being passed into method, later on I see two contridicting things:
    Code:
    Y_dst1[0] = …; Y_dst1[1] = …;
    and another bit
    Code:
    Y_dst1 += 2;
    From what I can understand, argument is a regular reference of type uint8.
    So what square brackets has to do with it? Is it access to particular bit?
    Also method comments tells me that parameter represents row of values (e.g. array), but again, I can't see any signs of that value being passed as an array.
    Any ideas?
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    It's a pointer to uint_8. The first two access the item pointed by it and the next one, the last advances the pointer by two items.

    Comment

    • Geo Ferdinend

      #3
      Re: Array or not

      For your problem, the solution could be like this.
      Please look into the code.

      Code:
      #include<iostream>
      #include<conio.h>
      using namespace std;
      
      typedef unsigned char uint8;
      
      void main()
      {
      	uint8* Y_dst1; // Nothing but unsigned character pointer
      
      	Y_dst1 = new uint8[10];
      
      	Y_dst1[0] = 'G'; 
      	Y_dst1[1] = 'o'; 
      	Y_dst1[2] = 'o';
      	Y_dst1[3] = 'd';
      	Y_dst1[4] = '\0';
      
      	cout << Y_dst1 << endl; // It will print Good
      	Y_dst1 += 2; 
      	cout << Y_dst1 << endl; // It will print od
      }

      Comment

      Working...