Donate to us via Paypal!
One mans freedom fighter, another's terrorist.
Monday, March 01, 2021
Navigation
Home
 Find:
 Information:
Learn
Communicate
Submit
Shop
Challenges
 Exploit:
 Programming:
 Think:
 Track:
 Patch:
 Other:
 Need Help?
Other
Members Online
Total Online: 119
Guests Online: 119
Members Online: 0

Registered Members: 133766
Newest Member: denim6321d
Latest Articles

View Thread

HellBound Hackers | Computer General | Programming

Author

Determine the Output of this Code in C

Scar0ptics
Member



Posts: 229
Location: ∆ P®0X¥ W0R|D ∆
Joined: 19.11.13
Rank:
Mad User
Posted on 16-11-16 01:34
Run this through a Linux compiler using g++ and play around with the values within the array. I have posted the solutions, but I did not run this through a compiler, so there might be errors.

#include <stdio.h>

int main(){
int x [5];
x[0] = 10;
x[1] = 30;
x[2] = 50;
x[3] = 70;
x[4] = 99;
int *y = x;

printf("%d\n", *y+2); // 12
printf("%d\n", *(y+2)); // 50
printf("%d\n", x[5]); // writes random number from system memory.
printf("%d\n", y); // writes random number from system memory.

}
overlay-network.ddns.net
Author

RE: Determine the Output of this Code in C

Huitzilopochtli
Member



Posts: 1644
Location:
Joined: 19.02.13
Rank:
God
Posted on 16-11-16 03:06
Is answer Spag ?
Author

RE: Determine the Output of this Code in C

_spartax_
Member



Posts: 33
Location: SYSTEM
Joined: 03.06.16
Rank:
HBH Guru
Posted on 16-11-16 03:39
the stack layout is

HIGH MEMORY
x[4]
x[3]
x[2]
x[1]
x[0]
y == &x[0]
LOW MEMORY


Author

RE: Determine the Output of this Code in C

Scar0ptics
Member



Posts: 229
Location: ∆ P®0X¥ W0R|D ∆
Joined: 19.11.13
Rank:
Mad User
Posted on 16-11-16 13:20
Huitzilopochtli wrote:
Is answer Spag ?


Damn it Bobby, raise your hand. We need to ask Mordak if we can add a section for all the SPAG folks at HBH Tee-Hee-HeePfft


Thanks for sharing that _spartax_
overlay-network.ddns.net