【发布时间】:2016-05-10 20:33:04
【问题描述】:
我在公司面试,被问了一个问题,问题有点奇怪所以想请教高手。
问题假设我有返回 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
}
该算法应该是什么?
【问题讨论】:
-
你显示的那个函数,不是C。请使用正确语言标签。
-
有点奇怪,
C采访(如您标记的那样)会询问bool(而不是_Bool,例如参见 Is bool a native C type?)。另请参阅上面@JoachimPileborg 的评论。也许是C++?这不是一回事,有些面试官会注意这种混淆。 -
TIL:
!是一个算法。 -
如果你不知道,申请工作就是浪费大家的时间。您需要一门入门编程课程。
-
@dxiv 没什么奇怪的,
bool比_Bool更常用。不过,public的使用非常奇怪。
标签: c algorithm data-structures