kainster

never too late
posts - 33, comments - 3, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

printf( "%c\n", *("xyz"+1) );

Posted on 2008-10-19 11:14 kainster 阅读(140) 评论(0)  编辑  收藏 所属分类: 《C&Pointer》笔记
printf( "%c\n", *("xyz"+1) );
将会输出y
因为"xyz"实际上是指向字符串常量的指针,对它加1就是把指针向后移一个位置,所以指向y
 
类似的
#include <stdio.h>


void mystery( int n)
{
    n 
+= 5;
    n 
%= 10;
    printf( 
"%s\n""**********"+10-n );
}


int main()
{
    
int i;

    
for( i=0; i<20; i++ )
        mystery( i );
}
运行结果为

*****
******
*******
********
*********

*
**
***
****
*****
******
*******
********
*********

*
**
***
****
Press any key to continue



只有注册用户登录后才能发表评论。


网站导航: