最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關(guān)于C語言指針賦值的問題詳解

 更新時(shí)間:2013年05月15日 10:33:08   作者:  
本篇文章是對(duì)C語言指針賦值的問題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下

一個(gè)代碼:

復(fù)制代碼 代碼如下:

#include<stdio.h>
#include<stdlib.h>
#define uchar unsigned char
#define uint unsigned int

void display(uchar *p);

char h[4] = {'A','B','C','\0'};
char e[4] = {'E','F','L','\0'};
char l[4] = {'M','N','O','\0'};
char o[4] = {'X','Y','Z','\0'};

int main(void)
{
    int i;
    char c;
    uint set[5];

    set[0] = h;
    set[1] = e;
    set[2] = l;
    set[3] = l;
    set[4] = o;

       while(1){
           for (i = 0; i < 5; ++i){
                display(set[i]);
                printf("\n");
                sleep(1);

          }

       }
}

void display(uchar *p)
{
   while(*p != '\0'){
    printf("%c", *p);
    printf("%c", *(p+1));
    ++p;
    }
}


警報(bào)如下:

test.c:21: 警告: 賦值時(shí)將指針賦給整數(shù),未作類型轉(zhuǎn)換
test.c:22: 警告: 賦值時(shí)將指針賦給整數(shù),未作類型轉(zhuǎn)換
test.c:23: 警告: 賦值時(shí)將指針賦給整數(shù),未作類型轉(zhuǎn)換
test.c:24: 警告: 賦值時(shí)將指針賦給整數(shù),未作類型轉(zhuǎn)換
test.c:25: 警告: 賦值時(shí)將指針賦給整數(shù),未作類型轉(zhuǎn)換
test.c:29: 警告: 傳遞參數(shù) 1 (屬于 ‘display')時(shí)將整數(shù)賦給指針,未作類型轉(zhuǎn)換

其中21-25就是
set[0] = h;
set[1] = e;
set[2] = l;
set[3] = l;
set[4] = o;
29是
display(set[i])

雖然只是警報(bào),并且在linux下面也可以運(yùn)行的很好.但是既然警告了.還是值得討論下.

待續(xù)~
關(guān)注中...

如果有哪位知道.可否回復(fù)告訴我.謝謝~

------------------------------------------------------------

關(guān)于這個(gè)問題,我問了寢室的小丁.經(jīng)過他的修改.程序已經(jīng)不報(bào)警告了.

復(fù)制代碼 代碼如下:

#include<stdio.h>
#include<stdlib.h>
#define uchar unsigned char
#define uint unsigned int

void display(uchar *p);

char h[4] = {'A','B','C','\0'};
char e[4] = {'E','F','L','\0'};
char l[4] = {'M','N','O','\0'};
char o[4] = {'X','Y','Z','\0'};

int main(void)
{
    int i;
    char c;
    int set[5];

    set[0] =(int) h;
    set[1] =(int) e;
    set[2] =(int) l;
    set[3] =(int) l;
    set[4] =(int) o;

       while(1){
           for (i = 0; i < 5; ++i){
                display((uchar *)set[i]);
                printf("\n");
                sleep(1);

          }

       }
}

void display(uchar *p)
{
   while(*p != '\0'){
    printf("%c", *p);
    printf("%c", *(p+1));
    ++p;
    }
}


在字模數(shù)組的首地址賦值方面用了強(qiáng)制轉(zhuǎn)換為int.在函數(shù)調(diào)用方面.因?yàn)樽雍瘮?shù)中要求到輸入為指針,所以在前面的調(diào)用時(shí)候,不能單純的寫set[i].而是傳指針過去.(uchar *)的強(qiáng)制類型轉(zhuǎn)換是為了配合(uchar *p).
-------------------------------------------
應(yīng)該注意的2點(diǎn)是:
1.給指針只能傳地址,不能傳值.否則要做強(qiáng)制類型轉(zhuǎn)換.
2.在做類型轉(zhuǎn)換和賦值時(shí)候,應(yīng)該注意賦值的類型匹配.

相關(guān)文章

最新評(píng)論

宾川县| 天峨县| 郎溪县| 临泉县| 东乌| 丹凤县| 陆河县| 商丘市| 民和| 页游| 湘阴县| 南郑县| 尉氏县| 新巴尔虎左旗| 迭部县| 盐城市| 兴隆县| 长阳| 永年县| 江孜县| 得荣县| 稷山县| 克什克腾旗| 鹰潭市| 阿瓦提县| 崇阳县| 平遥县| 西乡县| 鱼台县| 遂溪县| 昌黎县| 黄石市| 尼木县| 榆社县| 安宁市| 高邮市| 扶余县| 海口市| 阳原县| 茶陵县| 隆子县|