我正在通过Sololearn学习C++.下面是一个代码,用于查找两个数字中最大的一个.
#include <iostream>
using namespace std;
int max(int a, int b){
if (a > b) {
return a;
}
return b;
}
int main() {
cout << max(7, 4) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
结果 - 7
但是它不应该返回b因为函数中有返回b ????
我找到了一个在函数原型设计和声明中使用不同参数的程序,所以我制作了一个基本程序.
#include <iostream>
using namespace std;
void add(int a, int b);
int main()
{
add(3,4);
}
void add(int c, int d){
int e = c + d;
cout << e << endl;
}
Run Code Online (Sandbox Code Playgroud)
我运行这个程序,它的工作原理.这是否意味着在"功能原型设计"和"功能声明"中都没有必要使用相同的参数名称?
我正在关注这个视频教程(C++/游戏教程 8:随机数生成器)。我编写了该程序,但每次都得到相同的输出。
#include <iostream>
#include <random>
#include <string>
#include <ctime>
using namespace std;
int main()
{
default_random_engine randomGen(time(0));
uniform_int_distribution<int> diceRoll(1, 6);
cout << diceRoll(randomGen) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用 Code::Blocks。我在Visual Studio中尝试过,效果很好。这是否意味着这是 Code::Blocks 问题?