Incredible C++ Snippet
September 24th, 2008
Please have a look at this code snippet and try to tell me what you’re expecting it to print out.
#include <iostream> using namespace std; int main() { int x,y; int feld[5]; x=6; for(y=0;y<=5;y++) { feld[y] = 1; cout << y << endl; } cout << x << endl; return 0; }
Mention that the array size is 5 and the for loop goes till 5 (including!).
If you don’t get the solution why this happens the way it happens it might help you to know changing the order of decleration of x and y does cause a totally different output.
I will give you the solution to that miracle in a few days…
Have fun ![]()






[…] think it’s time to disclose the secret of that peace of code. First of all it’s not that tricky as you might have expected. You just have to […]
Pingback by Kai’s Blog » Incredible C++ Snippet - How it works — September 24, 2008 @ 8:00 pm