关于C++变量特殊符号
  • 板块灌水区
  • 楼主__szh_DNCB__
  • 当前回复9
  • 已保存回复10
  • 发布时间2024/4/5 21:38
  • 上次更新2024/4/6 06:49:40
查看原帖
关于C++变量特殊符号
1073754
__szh_DNCB__楼主2024/4/5 21:38

刚才看见有个帖子说$符号可以用于变量命名。

简单测试了一下,以下程序在Dev-C++,洛谷IDE和某评测平台上均显示可以编译:

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a$;a$ = 1;
	cout << a$;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
	int $a;$a = 1;
	cout << $a;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
	int $;$ = 1;
	cout << $;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
	int $a;cin >> $a;
	cout << $a;
	return 0;
}

然后和老师去找了一下原因,只有知乎上有一篇回答说是编译器原因。

但我不相信这么多IDE都有编译器上的问题。所以提出以下几点问题:

  1. $到底能不能做变量名?
  2. 如果$能做变量名,那么变量名只能由字母、数字、下划线组成的理论还成立吗?
  3. 如果CSP初赛再考如Q2中的理论,怎么回答?
2024/4/5 21:38
加载中...