C++ Tips:signed main 和 int main 的区别?

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    return 0;
}

注意到 #define int long long 而 main 函数必须返回一个 int 值,所以不能使用 int main()

通常使用 signed main,因为 signed 等效替代于 signed int,也就是有符号整型,这与 int 别无二致,但不会导致超出范围

c++ - Difference between signed main() and int main()? - Stack Overflow

  int main doesn't return -signed main returns . You have defined a macro named .intlong longint

Speaking of which, defining a macro with the name that matches a keyword exhibits undefined behavior.

posted @ 2022-11-20 18:47  slowlydance2me  阅读(188)  评论(0编辑  收藏  举报