May 16, 2008

Array Pointers Can Be Backwards - (Kind of)

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

free web hosting

Array Pointers Can Be Backwards - (Kind of)

hippiman
I just found this out today:
When you're using arrays, when you reference a certain index, you can switch the pointer and the subscript around. I know I'm not explaining that very good, but here's and example:

CODE
int a[] = {1,2,3,4,5,6,7,8,9,10,11};
int b =1;
int c[] = {0,-5,11,0,0,5,0,0,0};
cout << b[a][c];    //Same as c[a[b]];


See? 'b' is actually just an integer, it's not an array, or pointer, or anything. Usually, you would have to put the array first, then an integer.
Like if you have an array of type int, of length 5, you could reference something at index 3 using:
CODE
a[3]
//OR
3[a]


It doesn't really make sense, but I found this on a forum, as someone's signature:
CODE
int main() {
    char o[1920]={0};
    int _;
    double l[]={0,-5,11,0,0,5,0,0,0},_1=0.174533;
    for(_=0;_<36;++_)
        (((int)(2[l]=((cos(_1)*(4[l]=2[l]))+(sin(_1)*7[l])))+12)*80
        +((int)(7[l]=((cos(_1)*7[l])-(sin(_1)*4[l])))+40))[o]=_<27?(((int)(8[l]=((cos(-_1)
        *(6[l]=8[l]))+(sin(-_1)*5[l])))+8)*80+((int)(5[l]=((cos(-_1)*5[l])-(sin(-_1)*6[l])))
        +40))[o]=(((int)(1[l]=((cos(_1)*(0[l]=1[l]))+(sin(_1)*3[l])))+16)*80+((int)(3[l]=
        ((cos(_1)*3[l])-(sin(_1)*0[l])))+40))[o]='*':'*';
    _=0;
    while(_<1920)putchar(_++[o]);
}
//don't forget to include iostream and use namespace std

That was actually more garbled when it was in their signature, I just indented it, and added new lines where the semicolons were.
What really confused me was that they used and underscore as a variable(hard to see in a signature, I thought it was a space or something), and there were some parts where they switched the pointer and the subscript for an array (like in that last 'while').
All this really does is print out a bunch of asterisks in the shape of an 's' with a circle around it.

I'm pretty sure that the way they coded that isn't good practice, they were just trying to condense it a lot so they could fit it in their signature.
But hey, I guess I learn something new every day. wink.gif

 

 

 


Reply

osknockout
blink.gif WoW! That's really cool actually. Heh, after forever I'm learning something new about C++. yay. Wouldn't that mess up if both were defined though? E.g. your a[3] = 3[a] thing. If I made an int array named 3 and an int array named a, that wouldn't work anymore, would it?

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. php indexing array backward - 226.80 hr back.
Similar Topics

Keywords : array pointers backwards

  1. Array Problem - (4)
  2. Opengl Pointer To Array - Value Pointed..? (1)
    I'm playing around wtih openGL and trying to get the hang of c/c++(very frustrating at times). I
    pass a pointer to an array from an object to my main via a get method. If I print out(cout) the
    pointer(p) and the value pointed to (*p) from main, *p prints the decimal equivilent of the memory
    address p, not the value that p should be pointing to. Within the object, everything is peachy, its
    just when I pass the pointer to to main that this happens. The arrays plist and vlist in
    meshloader are the ones im having trouble with. Any ideas? Thanks in advance. Feel free t...
  3. 32-bit Pointers - FAR pointers (2)
    Here I enjoy using trap17, as it help me getting my answers. Can anybody find a some useful
    materials on FAR,NEAR and HUGE pointers. I wanna access the memory above 640kb in turbo C/C++ and
    mail acumentech@gmail.com thanks...
  4. Array Size Limitations - (2)
    I'm writing a win32 console app and am about to implement an array of size 10,000,000 . Can
    someone tell me what this would do ? Would my memory be able to handle it or would it cause other
    variables to lose their value ? I may just end up writing the array to a text file and then just
    searching it when I need it but I would rather not if I didn't need to. Can someone tell me what
    the limit is ? kvarnerexpress...



Looking for array, pointers, backwards, kind,

Searching Video's for array, pointers, backwards, kind,
advertisement



Array Pointers Can Be Backwards - (Kind of)



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE