分配中不兼容的类型 [英] incompatible types in assignment

查看:70
本文介绍了分配中不兼容的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

行号中的代码有什么问题。 7?!


#cat test3.c

#include< stdio.h>


int main (int argc,char * argv [])

{

int ia1 [10] = {0,1,2};

int ia2 [10];

ia2 = ia1;


printf("%d \ nn",ia2 [2]);


返回0;

}

#gcc test3.c

test3.c:在函数`main'中':

test3.c:7:作业中不兼容的类型



Whats wrong with the code in line no. 7?!

#cat test3.c
#include <stdio.h>

int main(int argc, char *argv[])
{
int ia1[10] = {0, 1, 2};
int ia2[10];
ia2 = ia1;

printf("%d\n", ia2[2]);

return 0;
}
#gcc test3.c
test3.c: In function `main'':
test3.c:7: incompatible types in assignment
#

推荐答案

v4vijayakumar说:
v4vijayakumar said:
行代码中的代码有什么问题。 7?!

#cat test3.c
#include< stdio.h>

int main(int argc,char * argv [])
{
int ia1 [10] = {0,1,2};
int ia2 [10];
ia2 = ia1;

printf(" ;%d \ n",ia2 [2]);

返回0;
}
#gcc test3.c
test3.c:在函数中main'':
test3.c:7:赋值中不兼容的类型
Whats wrong with the code in line no. 7?!

#cat test3.c
#include <stdio.h>

int main(int argc, char *argv[])
{
int ia1[10] = {0, 1, 2};
int ia2[10];
ia2 = ia1;

printf("%d\n", ia2[2]);

return 0;
}
#gcc test3.c
test3.c: In function `main'':
test3.c:7: incompatible types in assignment




你不能用C语言分配数组。它们是左值,但是不是可修改的

lvalues。


修复:


#include< string.h> <然后,如果两个阵列具有相同的大小和类型,你可以用这个来替换你的作业尝试。


memcpy(ia2,ia1,sizeof ia2);


-

Richard Heathfield

" Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)



You can''t assign to arrays in C. They are lvalues, but not "modifiable
lvalues".

Fix:

#include <string.h>

and then, provided the two arrays are of the same size and type, you can
replace your assignment attempt with this::

memcpy(ia2, ia1, sizeof ia2);

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


另外。

int main(int argc,char * argv [])

{

int ia1 [10] = {0,1,2};

int * ia2;

ia2 = ia1;


printf("%d \ n",* ia2 + 2) ;


返回0;


}


v4vijayakumar写道:
Also.

int main(int argc, char *argv[])
{
int ia1[10] = {0, 1, 2};
int *ia2;
ia2 = ia1;

printf("%d\n",*ia2+2);

return 0;

}

v4vijayakumar wrote:
排队的代码有什么问题。 7?!

#cat test3.c
#include< stdio.h>

int main(int argc,char * argv [])
{
int ia1 [10] = {0,1,2};
int ia2 [10];
ia2 = ia1;

printf(" ;%d \ n",ia2 [2]);

返回0;
}
#gcc test3.c
test3.c:在函数中main'':
test3.c:7:作业中不兼容的类型
Whats wrong with the code in line no. 7?!

#cat test3.c
#include <stdio.h>

int main(int argc, char *argv[])
{
int ia1[10] = {0, 1, 2};
int ia2[10];
ia2 = ia1;

printf("%d\n", ia2[2]);

return 0;
}
#gcc test3.c
test3.c: In function `main'':
test3.c:7: incompatible types in assignment
#






#include< stdio.h>


int main(int argc,char * argv [])

{

int ia1 [10] = {0,1,2};

int * ia2;

ia2 = ia1;


printf("% d \ n,*(ia2 + 2));


返回0;


}


v4vijayakumar写道:
#include <stdio.h>

int main(int argc, char *argv[])
{
int ia1[10] = {0, 1, 2};
int *ia2;
ia2 = ia1;

printf("%d\n",*(ia2+2));

return 0;

}

v4vijayakumar wrote:
行中没有错误的代码。 7?!

#cat test3.c
#include< stdio.h>

int main(int argc,char * argv [])
{
int ia1 [10] = {0,1,2};
int ia2 [10];
ia2 = ia1;

printf(" ;%d \ n",ia2 [2]);

返回0;
}
#gcc test3.c
test3.c:在函数中main'':
test3.c:7:作业中不兼容的类型
Whats wrong with the code in line no. 7?!

#cat test3.c
#include <stdio.h>

int main(int argc, char *argv[])
{
int ia1[10] = {0, 1, 2};
int ia2[10];
ia2 = ia1;

printf("%d\n", ia2[2]);

return 0;
}
#gcc test3.c
test3.c: In function `main'':
test3.c:7: incompatible types in assignment
#






这篇关于分配中不兼容的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆