2013. 3. 30. 15:42
이차원배열과 그 순회방법 C언어 이야기2013. 3. 30. 15:42
int main()
{
char s[3][20] = {"helloworld", "the end", "good boy"};
char (*ptr)[20] = s; //2차원 배열을 가르키기 위해 다음과 같은 문법을 이용한다.
int i;
for(i = 0 ; i < 3; i++)
{
printf("%s \n", *ptr++); //*ptr 하고, ptr++
}
return 0;
}
int main()
{
char s[3][20] = {"helloworld", "the end", "good boy"};
char (*ptr)[20] = s;
int i;
for(i = 0 ; i < 2; i++)
{
printf("%s \n", *++ptr); //++ptr, 하고 *
}
return 0;
}
상식수준에서 생각하자. *ptr++이면, 역참조부터 하고, 증가시킨다고 생각한다.
*++ptr이면, ++하고, *한다고 생각한다.
'C언어 이야기' 카테고리의 다른 글
C언어 형변환... (1) | 2013.05.25 |
---|---|
static 배열과 auto 배열의 차이 (0) | 2013.05.17 |
linux hlist 분석 (0) | 2013.02.09 |
공유라이브러리 연습 (0) | 2013.01.28 |
int ** vs int (*)[] 이차원배열 (0) | 2012.12.18 |