一维和二维数组在使用过程中,经常会出错,将常用列出来,以便加深印象。
unsigned int str2ptr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
unsigned int *str1ptr1= str2ptr[1];
log->debug(QString().sprintf("str1ptr1 1st is 4: %d", str1ptr1[0]));
log->debug(QString().sprintf("str1ptr1 2st is 5: %d", str1ptr1[1]));
str1ptr1++;
log->debug(QString().sprintf("str1ptr1++ 1st is 5: %d", str1ptr1[0]));
log->debug(QString().sprintf("str2ptr 1st is 1: %d", str2ptr[0][0]));
log->debug(QString().sprintf("str2ptr 2st is 2: %d", str2ptr[0][1]));
log->debug(QString().sprintf("str2ptr 4st is 4: %d", str2ptr[1][0]));
log->debug(QString().sprintf("str2ptr+1 1st is 2: %d", str2ptr[0][0]+1));
log->debug(QString().sprintf("str2ptr[0] 1st is 1: %d", *(str2ptr[0])));
log->debug(QString().sprintf("str2ptr[0]+1 1st is 2: %d", *(str2ptr[0]+1)));
log->debug(QString().sprintf("str2ptr[1] 1st is 4: %d", *(str2ptr[1])));
log->debug(QString().sprintf("str2ptr[1]+1 1st is 5: %d", *(str2ptr[1]+1)));
打印出来的结果: