• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Brainbuster reposted correctly (GOD I hate HTML)

This topic is 6890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, here''s the brainbuster again, correctly typed, and displayed (I think) And it wasn''t meant to be a test of syntax errors, that was purely due to the HTML. It was meant to be a test of pointer knowledge etc..., and this code will compile, (if I''ve got it to display correctly). Let''s see if it worked this time. If not, then I''ll stop posting garbage.
int main(int argc, char *argv[]){
int x = 0;
char a[26] = {''a'', ''b'', ''c'', ''d'', ''e'', ''f'', ''g'',
''h'', ''i'', ''j'', ''k'', ''l'', ''m'', ''n'',
''o'', ''p'', ''q'', ''r'', ''s'', ''t'', ''u'',
''v'', ''w'', ''x'', ''y'', ''z''};
for(int i=0; i < 8; i++){
x += i;
cout << x [ a ] << endl;
}
return 0;
}


##### Share on other sites
Ok, that is correctly typed in, reply away my litttle chick-a-dees, oddly enough, I just found an example of this method in the ANSI C 3rd edition. I''ll check this thread a little later and reply with the answer if nobody gets it.

Jon Stelly

##### Share on other sites
Ah, now that''s a much more interesting question. My stab at the answer (I''ll explain later if I''m told I''m correct):
abdgkpv*junk* (out of array, unknown output char)

##### Share on other sites
Hej,

you had me for a second. This is a cool one. With ( and ) i actually mean the square brackets.

But x(a) is basically the same as a(x). This is because it doesn't matter whether you switch base and index cause all that happens is that they are added together to obtain the final adress.

This could become a problem when the size of the elements are bigger then a byte but I haven't thought about that one yet.

I was a little bit surprised that my compiler allowed indexing of non pointer types however.

The output of the program by the way should not be hard to find out by the way. It's the same when you do a(x). Also note that you are reading out of the array boundaries. THe answer as in the message above this one is correct.

Correct me if i'm wrong!

Jaap Suter

Edited by - s9801758 on 3/8/00 4:50:24 PM

##### Share on other sites
Shite square brackets! .

Sorry for the double post.

Edited by - s9801758 on 3/8/00 4:51:47 PM

##### Share on other sites
in the for loop, shouldn''t you do something more like this?:
 x++; cout< }//end for loop

rather than this
x += i;cout<}//end for loop

or you could just screw x and do this:
for(int i;i=0;i++){ cout<<}//end for loop

You see, if you just went through the for loop using the x+= i, then this is what would happen:

i value     x value1           12           33           64           105           156           217           288           369           4510          55

see? You''re adding the current value of i to the current cumulating value of x .And then you printed to the screen x[a]. Why? x is not an array of integers. I think that you wanted to do a[x] because a is an array of chars. I think that you just accidentally switched them. Oh, and by the way, If the table that I put up there is screwed up, then I''ll try to put it up again. '' Target=_Blank>Link

"Remember, I'm the monkey, and you're the cheese grater. So no fooling around."
-Grand Theft Auto, London

##### Share on other sites
Great job fellas, both of you are right, and the array bounds issue was one of the things that he wanted me to catch.

I think I might have to find some way to use this in this years obfuscated C competition. I got it after reading through it a second time, but at least the person interviewing got a kick out of it when I started grinning ear to ear when I saw the answer.

##### Share on other sites
PsYcHoPrOg No

x+=i <=> x=x+i;
x++ <=> x=x+1;

x+=i simulation;

i 0 1 2 3 4 5 6 7
x 0 1 3 6 10 15 21 28

x++ simulation;

i 0 1 2 3 4 5 6 7
x 0 1 2 3 4 5 6 7

Hope this clears the issue ;p

##### Share on other sites
erm, (Mithrandir Raises his hand) excuse me teacher, but whats the point of this? If anyone ever actually uses code like this they should be shot on sight

sorry, but I''m comming from an engineering perspective here, and even knowing this stuff seems pretty worthless to me.

===============================================
I saw a man pursuing the horizon;
Round and round they sped. I was disturbed at this; I accosted the man.
"It is futile," I said, You can never -- "

"You lie," he cried, And ran on.

##### Share on other sites
Mithrandir: You are right, no one should write code like this. But the point is that you need to understand how it works when you come across it while debugging other peoples code. Believe me, you will see a lot of stupid code once you start working with other engineers.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 17
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634094
• Total Posts
3015498
×