刚才看见有个帖子说$符号可以用于变量命名。
简单测试了一下,以下程序在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都有编译器上的问题。所以提出以下几点问题:
$到底能不能做变量名?
- 如果
$能做变量名,那么变量名只能由字母、数字、下划线组成的理论还成立吗?
- 如果CSP初赛再考如Q2中的理论,怎么回答?