| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1178 人关注过本帖
标题:请问各位朋友关于变量赋初值的问题?
只看楼主 加入收藏
jiujiuwan
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2018-10-21
收藏
 问题点数:0 回复次数:3 
请问各位朋友关于变量赋初值的问题?
请问int t=0;跟int t(0);
这两种赋值方法有什么不同,第二种来自哪里呢,为什么从来都没有见过?
程序代码:
#include<stdio.h>
int main(){
    //int a(3003);
    int a = 3003; 
    printf("%d",a);
    return 0;
}

以上两种方法得到的结果是一样的!
搜索更多相关主题的帖子: 变量 初值 int 方法 printf 
2019-06-17 15:51
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
你确定用的是C编译器,而非C++编译器?!
2019-06-17 16:01
燕小六
Rank: 4
来 自:北京
等 级:业余侠客
威 望:3
帖 子:49
专家分:247
注 册:2017-11-29
收藏
得分:0 
标准C里面,比如GCC肯定不可以int a(10)这样

程序代码:
root@localhost:~# cat a.c 
#include<stdio.h>
int main(){
    int a(3003);
    // int a = 3003; 
    printf("%d",a);
    return 0;
}
root@localhost:~# gcc a.c 
a.c: In function 'main':
a.c:3:11: error: expected declaration specifiers or '...' before numeric constant
     int a(3003);
           ^
a.c:5:17: error: 'a' undeclared (first use in this function)
     printf("%d",a);
                 ^
a.c:5:17: note: each undeclared identifier is reported only once for each function it appears in
root@localhost:~# 
2019-06-17 16:18
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
    // C 和 C++ 都支持
    int a = 1;
    int b = { 1 };
   
    // 仅 C++ 才支持
    int c( 1 );
    int d = {};
    int e {};
    int f { 1 };
2019-06-17 16:24
快速回复:请问各位朋友关于变量赋初值的问题?
数据加载中...
 
   



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

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