By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Array or not?

P: n/a
I stumbled across strange bit of code (probably it's my lack of c syntax):
argument
Expand|Select|Wrap|Line Numbers
  1. uint8* Y_dst1
is being passed into method, later on I see two contridicting things:
Expand|Select|Wrap|Line Numbers
  1. Y_dst1[0] = ; Y_dst1[1] = ;
and another bit
Expand|Select|Wrap|Line Numbers
  1. 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?
Oct 6 '10 #1
Share this Question
Share on Google+
2 Replies


100+
P: 687
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.
Oct 7 '10 #2

P: n/a
For your problem, the solution could be like this.
Please look into the code.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4.  
  5. typedef unsigned char uint8;
  6.  
  7. void main()
  8. {
  9.     uint8* Y_dst1; // Nothing but unsigned character pointer
  10.  
  11.     Y_dst1 = new uint8[10];
  12.  
  13.     Y_dst1[0] = 'G'; 
  14.     Y_dst1[1] = 'o'; 
  15.     Y_dst1[2] = 'o';
  16.     Y_dst1[3] = 'd';
  17.     Y_dst1[4] = '\0';
  18.  
  19.     cout << Y_dst1 << endl; // It will print Good
  20.     Y_dst1 += 2; 
  21.     cout << Y_dst1 << endl; // It will print od
  22. }
  23.  
Oct 7 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.