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

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

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

一個代碼:

復(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;
    }
}


警報如下:

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

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

雖然只是警報,并且在linux下面也可以運行的很好.但是既然警告了.還是值得討論下.

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

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

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

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

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

相關(guān)文章

最新評論

丰顺县| 余干县| 拜泉县| 灵石县| 正阳县| 莒南县| 铜陵市| 成武县| 海伦市| 凤城市| 达拉特旗| 石林| 滨海县| 甘洛县| 铜川市| 安吉县| 望谟县| 辛集市| 东丰县| 巴东县| 宁明县| 开封市| 左云县| 邳州市| 广宁县| 石屏县| 渭南市| 万州区| 泸水县| 红河县| 承德市| 若羌县| 龙里县| 鹤峰县| 武安市| 西昌市| 灵璧县| 普陀区| 汝州市| 勃利县| 安顺市|