python可以不写函数返回值,这时默认是return None,类型是Nonetype
def a():
c=1+2
b = a()
print(type(b))
输出:
<class 'NoneType'>
对于main函数:
C语言如果不写返回值就默认return 0,不写返回值类型会默认int。
C++必须写返回值,且对于要求严格的编译器来说,C++的返回值必须是int,不能是void型。
C语言不写返回值类型时默认返回int,而C++不写返回值类型时,编译出错,出现如下提示:
错误 C4430 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int Project1 F:\ZhangY\c++\Project1\Project1\shuchu.cpp 3
所以,在日常习惯中,main函数返回值类型写上int 同时在最后加上return 0;