c语言中多个变量连续赋值

 

001、

复制代码
[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c          ##测试c程序
#include <stdio.h>

int main(void)
{
        int i,j;

        i = j = 5;                   // 连续赋值

        printf("i = %d\n", i);
        printf("j = %d\n", j);

        return 0;
}
[root@PC1 test]# gcc test.c -o kkk
[root@PC1 test]# ls
kkk  test.c
[root@PC1 test]# ./kkk
i = 5
j = 5
复制代码

 

002、

复制代码
[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c
#include <stdio.h>

int main(void)
{
        int i = j = 5;                 // 无法再初始化过程中连续赋值

        printf("i = %d\n", i);
        printf("j = %d\n", j);

        return 0;
}
[root@PC1 test]# gcc test.c -o kkk
test.c: In function ‘main’:
test.c:5:10: error: ‘j’ undeclared (first use in this function)
  int i = j = 5;
          ^
test.c:5:10: note: each undeclared identifier is reported only once for each function it appears in
复制代码

 

003、

复制代码
[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c              ## 测试c程序
#include <stdio.h>

int main(void)
{
        int array1[3] = {1,3,4};         // 数组可以连续赋值初始return 0;
}
[root@PC1 test]# gcc test.c -o kkk       ## 编译
[root@PC1 test]# ls
kkk  test.c
复制代码

 

004、

复制代码
[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c                        ## 测试c程序
#include <stdio.h>

int main(void)
{
        int array[3];

        array[3] = {1,3,8};                        //数组中不可以这样连续赋return 0;
}
[root@PC1 test]# gcc test.c -o kkk                  ## 无法编译
test.c: In function ‘main’:
test.c:7:13: error: expected expression before ‘{’ token
  array[3] = {1,3,8};
             ^
复制代码

 。

 

posted @   小鲨鱼2018  阅读(71)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-11-06 linux 中查看GNU c库版本 libc.so.6(GLIBC版本)
2023-11-06 configure: error: You need zlib >= 1.2.3 to build bin/PopLDdecay
2023-11-06 conda 升级到最新版本
2023-11-06 centos7 中 安装 rmblast 软件
2022-11-06 python中os模块下路径的常见操作
2021-11-06 docker pull越来越慢的解决方法
2021-11-06 Vmware虚拟机和docker在win10上不兼容的处理
点击右上角即可分享
微信分享提示