gpt4 book ai didi

c - 如何返回 true 或 false 的相反值?

转载 作者:行者123 更新时间:2023-11-30 21:47:15 27 4
gpt4 key购买 nike

我在公司面试,被问到一个问题,问题有点奇怪,所以想请教专家。

问题假设我有返回 bool 类型的函数。让我们这样说:

public bool func(int param)
{
bool retVal;

// here is some algorithm which as a result either set the retVal to false or true,
// It doesn't matter what is algo, the only thing important is it either do
// retVal=false or retVal=true

// The question is i have to write the algo here which in case
// if the previous algo gives us retVal=false then it should
// return true and if retVal=true then return false

}

该算法应该是什么?

最佳答案

我认为你的代码会是这样的:

public bool func(int param)
{
bool retVal;
return !retVal;
}

关于c - 如何返回 true 或 false 的相反值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35146662/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com