编译器的差别gcc和VS

1,下面分别gcc和VS上运行的是代码和分析区别

1,gcc代码

/*************************************************************************
 * 本题考点是gcc编译器  i++ 在遇到 '=' 符号时也是会增的不一定在一个循环继续后再自增的  
 * VS编译器 是在整个循环结束后才会i++的
    > File Name: 3strcpy的实现.c
    > Author: 
    > Mail: 
    > Created Time: Tue 08 Aug 2017 03:42:06 AM PDT
 ************************************************************************/

#include<stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    char s1[] = "Hello World!";
    char s2[20];
    int i = 0;


//    while (s1[i/*++*/])// 和下面的第2种情况一样的
  //  {
  //      s2[i/*++*/] = s1[i/*++ */];//1, 这里s2中已经i++ 后 有= 所以s1的地址 s1指向s1【1】2, 了s1 是直接错误的rr 
  //      i++;//ok
  //  }

   // s2[i] = '\0';

    //printf("while :%s\n", s2);
    for (i = 0; i < strlen(s1) ; i++)//ok
    {
        s2[i/*++*/] = s1[i/*++*/];//这里s2[i++] 的情况和while中s2{i++]情况一样 都和上面一样的 
        //i++; //ok
    }
    //s2 = '\0'; // gcc 编译器不需要 再末尾加'\0' VS 要加 '\0'
    printf("for : %s\n", s2);
    strcpy(s2, s1);

    printf("strcpy: %s\n", s2);
    return 0;
}

2,VS上的代码分析


/*************************************************************************
    > File Name:
    > Author: songli
    > Mail:
    > Created Time:
 ************************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>



int main(int argc, char *argv[])
{
    char str[] = "chensong chenli";
    char ch[30];

    //int i = 0;
    //while (str[i/*++*/])//err
    //{
    //  ch[i/**++ ok*/] = str[i/*++ ok */];
    //  i++;//ok
    //}

    //ch[i] = '\0';


    int i;
    for (i = 0; i < strlen(str); /*i++ok*/)
    {
        ch[i/*++ ok*/] = str[i/*++ok*/];
        i++;//ok
    }
    ch[i] = '\0';
    printf("ch = %s\n", ch);

    printf("\n");
    system("pause");
    return EXIT_SUCCESS;
}
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值