| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 850 人关注过本帖
标题:语义错误
只看楼主 加入收藏
kuaisha
Rank: 2
等 级:论坛游民
帖 子:120
专家分:30
注 册:2016-8-3
结帖率:100%
收藏
 问题点数:0 回复次数:2 
语义错误
程序代码:
#include<stdio.h>
#define N 5
void copy_arr(double source[],double target1[],int a);
void copy_ptr(double *source,double *target2,int b);

int main(void)
{
    double source[N]={1.1,2.2,3.3,4.4,5.5};
    double target1[N]={0};
    double target2[N]={0};
    printf("2ù×÷Ç°:\n "); 
    printf("source:\t%g\t%g\t%g\t%g\t%g\n",source[0],source[1],source[2],source[3],source[4]);
    printf("target1:\t%g\t%g\t%g\t%g\t%g\n",target1[0],target1[1],target1[2],target1[3],target1[4]);
    printf("target2:\t%g\t%g\t%g\t%g\t%g\n",target2[0],target2[1],target2[2],target2[3],target2[4]);
    copy_arr(source,target1,5);
    copy_ptr(source,target2,5);
    printf("2ù×÷oó:\n");
    printf("source :\t%g\t%g\t%g\t%g\t%g\n",source[0],source[1],source[2],source[3],source[4]);
     printf("target1:\t%g\t%g\t%g\t%g\t%g\n",target1[0],target1[1],target1[2],target1[3],target1[4]);
     printf("target2:\t%g\t%g\t%g\t%g\t%g\n",target2[0],target2[1],target2[2],target2[3],target2[4]);
    return 0;
}
void copy_arr(double source[],double target1[],int a)
{
    int i;
    for(i=0;i<a;i++)
    {
        source[i]=target1[i];
    }
     
}
void copy_ptr(double *source,double *target2,int a)
{
    int i;
    for(i=0;i<a;i++)
    {
        *(source+i)=*(target2+i);
    }
}

正确显示如下:
Before operation:
source :        1.1     2.2     3.3     4.4     5.5
target1:        0       0       0       0       0
target2:        0       0       0       0       0
After operation:
source :        1.1     2.2     3.3     4.4     5.5
target1:        1.1     2.2     3.3     4.4     5.5
target2:        1.1     2.2     3.3     4.4     5.5
搜索更多相关主题的帖子: void double source int printf 
2017-11-24 15:32
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏
得分:0 
        //source[i]=target1[i];
        target1[i]=source[i];

        //*(source+i)=*(target2+i);
        *(target2+i)=*(source+i);
2017-11-24 15:38
kuaisha
Rank: 2
等 级:论坛游民
帖 子:120
专家分:30
注 册:2016-8-3
收藏
得分:0 
回复 2楼 吹水佬
谢谢!
2017-11-24 15:55
快速回复:语义错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021388 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved