有什么理由我们需要无效功能吗?
出于与int main()
标准相同的原因,为什么不简单地0
从不需要返回值的函数返回?我看到使用int
类型有三个直接的好处:
1.我们可以返回一个代码来指示函数状态; 通常,如果出现问题,我们可以返回非零错误代码.
2.我们可以在调试时输出函数的返回值
3.它是main()例程的标准; 就是,int main() {}
.为什么不跟风呢?
是否有任何理由为什么我们宁愿void
过int
?
示例:对奶酪数组进行排序并通过引用返回的函数.
#include <iostream>
#include <string.h>
int sortArrayInt(string & _cheese[]) { // pun intended ;D
int errCode = 0;
try {
// ..sort cheese[] array
} catch(e) {
errCode = 1;
}
return errCode;
}
void sortArrayVoid(string & _cheese[]) {
// .. sort cheese[] array
// no return code to work with, doesn't follow int main() standard, and …
Run Code Online (Sandbox Code Playgroud) 对于这个问题,我得到了答案
$a = rand(100000,999999);
Run Code Online (Sandbox Code Playgroud)
我很困惑哪个最小值变量a可以采用,它将是100000还是100001?我想知道是否包括100000?
我正在做一个简单的点击游戏,我知道这是愚蠢的问,但我还在学习,所以我的问题是如何使"cost2"整数上升他的值+10每按一次按钮2.
这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Diamond_Clicker
{
public partial class Form1 : Form
{
private int clicks = 0;
private int counter = 1;
const double factor = 0.95;
double interval = 1000;
int cost = 50;
int cost2 = 500;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void UpdateButton()
{
if (clicks >= cost)
button1.Enabled = …
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,int()对这两个参数做了什么:
if (i=='0X0F'):
stat = int(log[i+1],16)
Run Code Online (Sandbox Code Playgroud)