为什么会出现使用了未初始化的局部变量

写一个SWAP(t,x,y),t为类型标识符,参数x和y是类型t,这个宏定义用来交换x和y的值
#include<stdio.h>
#define SWAP(t,x,y) {t x;t y;t tmp;tmp=x;x=y;y=tmp;printf("c=%d,d=%d",c,d);}
int main()
{
int c,d;
scanf("%d%d",&c,&d);
SWAP(int,c,d);
}
使用了未初始化的局部变量“c”
使用了未初始化的局部变量“d”
运用指针却不行
用这个宏定义来交换x和y的值

修改如下,供参考:

#include<stdio.h>
#define SWAP(t,x,y) {t tmp;tmp=x;x=y;y=tmp;printf("c=%d,d=%d",x,y);}  //t x;t y; printf("c=%d,d=%d",c,d);
int main()
{
    int c,d;
    scanf("%d%d",&c,&d);
    SWAP(int,c,d);

    return 0;
}

img

你c和d在SWAP中没定义啊,你的SWAP函数中的参数是t,x ,y 并没有定义c和d,因此没法这样使用。

希望对题主有所帮助!可以的话,帮忙点个采纳!