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;
}
Brainbuster reposted correctly (GOD I hate HTML)
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.
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
Jon Stelly
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)
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
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
____________________________Mmmm, I''ll have to think of one.
Shite square brackets! .
Sorry for the double post.
Edited by - s9801758 on 3/8/00 4:51:47 PM
Sorry for the double post.
Edited by - s9801758 on 3/8/00 4:51:47 PM
____________________________Mmmm, I''ll have to think of one.
in the for loop, shouldn''t you do something more like this?:
rather than this
or you could just screw x and do this:
You see, if you just went through the for loop using the x+= i, then this is what would happen:
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
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
D:
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.
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.
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
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
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.
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.
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement