ok so I have this C++ code:
#include "StdAfx.h"
#include <stdio.h>
#include <cstdlib>
using namespace std;
int main()
{
system("PAUSE");
typedef int ty[5];
ty sec[6];
for (int i=0;i<5;i++){
for(int j=0;j<6;j++){
sec[i][j]=i*6 +j;
printf("%d \t",i*6 +j);
printf("%d \n",sec[i][j]);
}}
int* p=sec[0];
for(int i=0;i<5;i++){for(int j=0;j<6;j++){printf("%d %d %d\n",sec[i][j],i,j);printf("%d\n",*p);
p++; }}
system("PAUSE");
}
(#include "StdAfx.h" is Visual Studio precompiler header)
what it does is preety obvious !
the problem is that the values printed are not what I expected them to be !
at the first loop everything is ok and sec[i][j] == i*5 +j
at the second one however things get nasty
when using the array ,the last element of every ty is 'missed'
(it prints 0 1 2 3 4 6 6 instead of 0 1 2 3 4 5 6)
when using pointers it gets even worse
can someone explain what I'm doing wrong ?
thanks a lot !!!