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 | |
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++ 的工作? : 太惨不忍赌了。就算你背下这个答也过不了的。
|