付翔的专栏
在鄙视中成长 记录成长的点滴
posts - 106,  comments - 32,  trackbacks - 0
今天 用指针的时候 遇到一个小问题 

#include <stdio.h>
#include 
<string.h>
#include 
<stdlib.h>
int cmp(const void *a,const void *b)
{
    
return strcmp((char *)a,(char *)b);
}

int main()
{
    
int i;
    
char str[4][5];
    
char **temp;
    strcpy(str[
0],"dbc");strcpy(str[1],"cbc");strcpy(str[2],"bbc");strcpy(str[3],"abc");
    
//temp = (char **)str;
//    i = 4;
    for(i =0 ; i < 4; i ++)
    {
        printf(
"%d:%s\t",str[i],str[i]);
    }
    printf(
"\n");
    
for(temp = (char **)str,i =0 ; i < 4; i ++)
    {
        printf(
"%d:%s\t",temp,temp);
        temp
++;//这里++ 是会错误的 他没有加 5个单位 只是加了四个
/*
1245032:dbc     1245037:cbc     1245042:bbc     1245047:abc
1245032:dbc     1245036:蘡bc    1245040:        1245044:c
*/
    }
    qsort(str,
4,sizeof(char)*5,cmp);
    printf(
"排序后\n");
    
for(i =0 ; i < 4; i ++)
    {
        printf(
"%d:%s\t",str[i],str[i]);
    }
    
return 0;
}
但是 我将 改成这个  strcpy(str[0],"bc");strcpy(str[1],"bc");strcpy(str[2],"bc");strcpy(str[3],"bc"); 也还是加 4 sizeof(char **) = 4;
无论什么指针都是 占四个字节 。

posted on 2010-07-03 23:41 付翔 阅读(132) 评论(0)  编辑 收藏 引用 所属分类: linux 及 c相关

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2010年7月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

CSDN - 我的blog地址

博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜