由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求指点一下我写的程序哪部分是C++ syntax
相关主题
问一个C的简单问题C++相关的面经
c++ 问题再问一个C的malloc( )
c interview question问道C内存的题?
请教一个指针的面试题菜鸟问个C++的pointer问题
菜鸟求救 请大家看看我的代码有没有问题How to find the size of an array? Thanks.
问个算法题给大家看几道C 小程序
一道 C++ 的题。大家新年好。 请教一个 c interview question (转载)
C++问题3问一个placement new 和 operator new的问题
相关话题的讨论汇总
话题: aliasnum话题: ids话题: alias话题: int话题: num
进入JobHunting版参与讨论
1 (共1页)
s*******1
发帖数: 33
1
去面试被要求用纯C写程序,不能有C++ syntax,我写的代码如下:
//Assume ids[] is to get specific_id in aliasID
//num is used to fix the length of ids[]
//alias is used to get the aliasID array
//aliasNum is used to get the length of array alias
/*
successFind = ture means return ids[] with length of num
successFind = false means return ids[] is null
or the length of ids[] is aliasNum (num > aliasNum)
*/
int* GetSomeIDs(int num, aliasID* &alias, int &aliasNum, bool& successFind)
{
successFind = true;
aliasNum = GetNumberOfAliases();
int idsNum = num;
//when num > aliasNum we try to return ids with the length of aliasNum
if(num > aliasNum)
{
printf("There are not enough alias was find and the found alias is %d n",
aliasNum);
successFind = false;
int* ids = (int*) malloc(aliasNum * sizeof(int));
idsNum = aliasNum;

if(aliasNum != 0 && ids == NULL)
{
//when there are not enough memory space for num of int (ids)
printf("There are not enough memory space for ids n");
idsNum = 0;
}
}
else
{
int* ids = (int*) malloc(num * sizeof(int));
}
alias = (aliasID*) malloc(aliasNum * sizeof(aliasID));
if(aliasNum != 0 && alias == NULL)
{
//when there are not enough momery space for aliasNum of aliasID
printf("There are not enough memory space for alias n");
free(ids);
successFind = false;
}
else
{
for(int i=0; i {
alias[i] = GetNextAlias();
}
}
if(alias)
{
for(int i=0; i ids[i] = alias[i] -> specific_id;
}
return ids;
}
被告知有C++ syntax, 但是我真的不知道哪些部分用到了C++ syntax,还有我程序有不
足的地方有大神来给指点一下吗?
b********0
发帖数: 62
2
引用& 好像是c++的
p*u
发帖数: 2454
3
use pointers instead of references.

【在 s*******1 的大作中提到】
: 去面试被要求用纯C写程序,不能有C++ syntax,我写的代码如下:
: //Assume ids[] is to get specific_id in aliasID
: //num is used to fix the length of ids[]
: //alias is used to get the aliasID array
: //aliasNum is used to get the length of array alias
: /*
: successFind = ture means return ids[] with length of num
: successFind = false means return ids[] is null
: or the length of ids[] is aliasNum (num > aliasNum)
: */

l*********u
发帖数: 19053
4
//是C++ :)
aliasNum = GetNumberOfAliases();
int idsNum = num;/* C++ */

【在 s*******1 的大作中提到】
: 去面试被要求用纯C写程序,不能有C++ syntax,我写的代码如下:
: //Assume ids[] is to get specific_id in aliasID
: //num is used to fix the length of ids[]
: //alias is used to get the aliasID array
: //aliasNum is used to get the length of array alias
: /*
: successFind = ture means return ids[] with length of num
: successFind = false means return ids[] is null
: or the length of ids[] is aliasNum (num > aliasNum)
: */

d********d
发帖数: 1424
5
能不能跳过C/C++ 的工作?
太惨不忍赌了。就算你背下这个答也过不了的。

【在 s*******1 的大作中提到】
: 去面试被要求用纯C写程序,不能有C++ syntax,我写的代码如下:
: //Assume ids[] is to get specific_id in aliasID
: //num is used to fix the length of ids[]
: //alias is used to get the aliasID array
: //aliasNum is used to get the length of array alias
: /*
: successFind = ture means return ids[] with length of num
: successFind = false means return ids[] is null
: or the length of ids[] is aliasNum (num > aliasNum)
: */

s*******1
发帖数: 33
6

不懂啊,什么叫背下答案啊?

【在 d********d 的大作中提到】
: 能不能跳过C/C++ 的工作?
: 太惨不忍赌了。就算你背下这个答也过不了的。

1 (共1页)
进入JobHunting版参与讨论
相关主题
问一个placement new 和 operator new的问题菜鸟求救 请大家看看我的代码有没有问题
bloomberg电面问个算法题
bloomberg onsite一道 C++ 的题。
Placement new的一个问题C++问题3
问一个C的简单问题C++相关的面经
c++ 问题再问一个C的malloc( )
c interview question问道C内存的题?
请教一个指针的面试题菜鸟问个C++的pointer问题
相关话题的讨论汇总
话题: aliasnum话题: ids话题: alias话题: int话题: num