由买买提看人间百态

topics

全部话题 - 话题: sizeof
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
r*****8
发帖数: 2560
1
C语言,结构体转字符串。简单的难题
结构体转字符串怎么做?我有一个野外站点,通过铱星发回来数据,10个字符1分
钱。为了降低费用,要压缩字符数量。结构体的位域(bit fields)很理想,以下例子
3个数据只要2个字符就够了。
结构体做好以后,要用字符传送(short burst message),怎么把结构体变成字
符串?我用的是个笨办法,把结构体写入一个文件。然后把文件的字符串读出来。
各位大侠有更好的方法吗?
如果有时间细看以下是程序。
// #############################################
#include // Standard input output.
#include // Standard library.
#include // String handling
#include /* POSIX terminal co... 阅读全帖
d****n
发帖数: 1637
2
来自主题: Programming版 - c的问题(2)
//use malloc with realloc
int size = 100;
int used =0;
float * array = malloc(sizeof(float)*);
for (int i=0;i<1000;i++){
if (i>=size){
size*=2
array = (float*)realloc(array,sizeof(float)*size);
}
array[used++] = float(i*100.);
}
free (array) ;
d***a
发帖数: 13752
3
来自主题: Programming版 - c的问题(2)
代码没有问题,可以这样写。你只是要保证分配的空间确实有N个element,否则会有数
组访问溢出。在机器代码层,MyArray[i]的实际意义是*(MyArray+i)。
你不用去管sizeof()的返回值。MyArray是个指针,存放的是内存地址,sizeof(
MyArray)返回的就是指针本身的字节数,在32位机器上就是4个字节。
s******e
发帖数: 2181
4
基本道理清楚,数组作为参数传递给函数的只是数组首元素的地址,函数在需要用到后
面元素时再按照这个地址和数组下标去查找。同时,数组名又正好是数组首元素的地址
,所以在主函数里调用子函数时只需写数组名,那么首元素的地址就传出去了。
我的问题来了,如下例,被调用的函数multiply的形参部分,float *p说明p是一个地
址,这个地址就是传过来的数组首元素的地址。既然p只是地址,那后面的操作
p[0]=2*p[0]
p[1]=2*p[1]
p[2]=2*p[2]
...
不是在把地址乘以2吗,怎么就变成把地址里面的内容乘以2了?用*p[...]来操作是不
是更符合情理?而且p既然是一个地址,怎么就可以写成p[...]了呢,这不变成地址数
组了吗?
虽然实际当中都在这样写,但心中的困惑一直都在。我不是专业马工,求专业马工解惑
并轻拍。
main()
{
float num[]={2.0,3.1,8.6,4.1,7.9};
const int size=sizeof(num)/sizeof(int);
multiply(num,size);
...
}
voi... 阅读全帖
p*****y
发帖数: 1049
5
来自主题: Programming版 - 设计一种c++语言的新特性
sizeof 必须在link之后才能得到
比如如果#include 然后link A.lib
这时候才能得到sizeof(A)
这样可以吗?
h*******s
发帖数: 24
6
来自主题: Unix版 - HELP gethostbyaddr()
What's wrong?
**************************
unsigned long ppp;
struct in_addr inaddr1;
ppp = inet_addr(hostname);
(void)memcpy(&inaddr1.s_addr,(char*)&ppp,sizeof
(inaddr1.s_addr));
if((hostaddress =
gethostbyaddr((char*)&inaddr1.s_addr,sizeof(inaddr1.s_addr),
PF_INET))==NULL);
{
}
******************************
What's wrong in the above section?
Can you send me an example about gethostbyaddr()?
my email address:
w*[email protected]
Thanks
h*******s
发帖数: 24
7
来自主题: Unix版 - help: gethostbyaddr()
What's wrong?
**************************
unsigned long ppp;
struct in_addr inaddr1;
ppp = inet_addr(hostname);
(void)memcpy(&inaddr1.s_addr,&ppp,sizeof (inaddr1.s_addr));
if((hostaddress =
gethostbyaddr((char*)&inaddr1.s_addr,sizeof(inaddr1.s_addr),
PF_INET))==NULL);
{
}
******************************
What's wrong in the above section?
Can you send me an example about gethostbyaddr()?
my email address:
w*[email protected]
Thanks
m******g
发帖数: 91
8
来自主题: Unix版 - 奇怪的 C 问题
【 以下文字转载自 Programming 讨论区 】
【 原文由 mangmang 所发表 】
这个程序在linux/x86上用gcc编译运行没有问题;
在Solaris(UNIX)机器上编译没问题, 但一运行就bus error.
这好像是跟机器有关系, 但还没整明白. 请大侠解惑. thx.
#include
#include
void fnFoo(void *pRow);
int main()
{
char *pTableRow;
int iRowSize;
/* the row looks like: int- char10 - int - char4
*/
iRowSize = sizeof(int) * 2 + sizeof(char) * 16;
pTableRow = (char *)calloc(1, iRowSize);
fnFoo(pTableRow);
printf("->%d<-\n", *(int*)pTableRow);
printf("->%s<-\n", (char*)
h***o
发帖数: 539
9
首先我怀疑即使long double也存不了这么多有效数字
实现还是有办法的
main()
{
long double code = 0.972384732814682914678216478321647832647382614738...;
int *p, i;
p = (int *) &code;
for (i = 0; i < sizeof(long double)/sizeof(int); i++)
printf("%08x", p[i]);
puts("");
}
再考虑到little_endian和big_endian的情况,这个问题还蛮复杂的。
Ag
发帖数: 481
10
来自主题: Computation版 - 请教大家c++ array
double **a;
a = (double **) malloc(200*sizeof(double *));
a[0] = (double *) malloc(200*sizeof(double));
for(i=0;i<200;i++){
a[i] = a[i-1]+200;
}
it's not elegant, but it should work.
w*******U
发帖数: 256
11
来自主题: Computation版 - fftw如何将plan作为子程序参数?
C语言程序用到 fftw, 如何将 plan 作为参数传递给子程序?下面的调用对么?
int main()
{
void myfun(int n1, int n2, int n3, double *phys, fftw_complex *spec, fftw_
plan pf, fftw_plan pb, ...);
......
int n1=64, n2=64, n3=64;
int n3c, n3r;
n3c=n3/2+1; n3r=2*n3c;
int rank=3, n[rank];
n[0]=n1; n[1]=n2; n[2]=n3;
double *phys; fftw_complex *spec;
phys=(double*)malloc(sizeof(double)*n1*n2*n3r);
spec=(fftw_complex*)fftw_malloc(sizeof(fftw_complex)*n1*n2*n3c);
fftw_plan pf, pb;
pf=fftw_plan_dft_r2c(rank, n, phys, spec, FFTW_MEASURE);
p... 阅读全帖
b******v
发帖数: 1493
12
C++程序如下
#include
using namespace std;
int main()
{
int a[] = {0, 1, 0, 0, 3, 5, 0, 0, 0, 4};
int p,n,q,m;
p = 0;
n = 1;
q = 0;
m = 1;
int N = sizeof(a)/sizeof(int);
for(int i=1; i if(a[i]==a[q]) {
m=m+1;
if(m>n) {
p = q;
n = m;
}
}
else {
q = i;
m = 1;
}
}
cout << "starting position is " << p << endl;
cout <<
f***a
发帖数: 329
13
C++ code如下。
输出结果对应我上面写的 R code, 不过我没把 detailed frequency显示出来。
#include
int main()
{
using namespace std;

int d[] = {1,1,1,2,2,1,1,2,2,1,1,1,3,3,3,1,1,1,3,2};
int num = 1;
int Ndata= sizeof d / sizeof d[0];
int n[Ndata];
int s[Ndata];
int l[Ndata];
int i=0;
n[i]=d[0]; s[i]=1; l[i]=1;
for (int k=1; k {
if(n[i]==d[k])
{
s[i]++;
}
else
{
i++; n[i]=d[k]; s[i]=1; l[i]=k+1;
}
}

in
w***n
发帖数: 1084
14
int tag[786];
int total_count=1000000;
int count=0;
for(int l=0; l {
memset(tag, 0, sizeof(int)*786);
for(int i=0; i<203; i++)
{
int id=RandomFloat()*786;
if(tag[id]==1) i--;
else tag[id]=1;
}
for(int i=0; i<786-5; i++)
{
if(tag[i]==1 && tag[i+1]==1 && tag[i+2]==1 && tag[i+3]==1 && tag[i+4
]==1)
{
count++;
break;
}
}
}
printf("probability: %f\n", (float)(count)/total_co
e*******r
发帖数: 1433
15
#define TOTAL 30
#define SLOTS 10
bool Search5Consecutive(int *data, int count)
{
for (int i=0;i {
if ((data[i] + 1 == data[i+1]) &&
(data[i] + 2 == data[i+2]) &&
(data[i] + 3 == data[i+3]) &&
(data[i] + 4 == data[i+4]))
{
return true;
}
}
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
int slot[SLOTS];
int i = 1;
__int64 count = 0, con_count = 0;
memset(slot, 0, sizeof(i
c*********d
发帖数: 9770
16
来自主题: Military版 - 袁岚峰 中国科学技术大学
https://zhuanlan.zhihu.com/p/36982992
袁岚峰
中国科学技术大学 微尺度物质科学国家实验室副研究员
关注风云之声提升思维层次
解读科学,洞察本质
戳穿忽悠,粉碎谣言
导读
联想2年前5G编码标准投票的历史被重提,“联想导致华为在投票中输给高通”成为群
众关注焦点。本文希望能还原一些事件真相,3GPP不存在所谓的投票定输赢的机制。联
想第二次会议中的异常行为对会议进程没有任何影响,并非华为方案没有通过的原因。
——————————————————————————————————————
联想2年前5G编码标准投票的历史,被旧事重提,“联想导致华为在投票中输给高通”
成为群众关注焦点。在中美正在进行贸易战与技术战争的背景下,联想受到了很大的舆
论压力,创始人柳传志都出来公开发声。
其实5G编码2016年底就有新闻,当时的说法是华为与西方列强斗争,主导的Polar码成
功成为国际编码标准。有一些了解技术的人还出来辟谣,说不是这回事,Polar码不是
华为发明的,也没有象吹的那样打败了对手。没想到2018年又被翻出来,但是说法却反
过来了,说华为5G编码之争... 阅读全帖
r******7
发帖数: 58
17
来自主题: JobHunting版 - Bloomberg电话面试真题并求答案
下面是本人近日在Bloomberg电话面试中被问到的题目及我自己的答案。面试后我问
考官我答得如何。他说因为面试是用同一套题目,所以不能告诉我哪题答对。这样说来
,这些题目可能对大家都有用。我贴一下向本版回馈。因为我的专业是EE,对这些编程
问题也没有把握。希望大家指出我回答中的错误。多谢。
注:题目以数字排序。以字母排序的是我的回答及注解。
Asked Questions
1. How to divide a number by 8 without using division?
a) Use bitwise shift >>3
2. What is register in C?
a) Register variables are stored in the registers in CPUs. Other
variables are stored in memory chips. Thus, register is faster.
3. The return of the sizeof functi
a*******y
发帖数: 1040
18
来自主题: JobHunting版 - 问个关于c++ auto_pter的问题
what do you mean ? why you say polymorphism here?
This auto_ptr class is not correct though. It has to maintain a ref and
refcount, it also need the assignment operator
I rewrote here:
template
class SmartPointer {
public:
SmartPointer(T * ptr) {
ref = ptr;
ref_count = malloc(sizeof(unsigned));
*ref_count = 1;
}
SmartPointer(SmartPointer & sptr) {
ref = sptr.ref;
ref_count = sptr.ref_count;
++*ref_count;
}
SmartPointer & operator=(SmartPointer & sptr) {
if (this != &sptr) {
re
p*********a
发帖数: 21
19
来自主题: JobHunting版 - 请教一道算法题
Here is the code to find the largest square matrix, for the rectangular, it's a bit more difficult. I will share the code if possible.
#include
#include
const int N = 100;
int d[N][N];
int m, n;
inline int minF(int a, int b, int c) {
return a }
int main()
{
freopen("in.txt", "r", stdin);
int i, j;
while(scanf("%d%d", &m, &n)!=EOF) {
memset(d, 0, sizeof(d));
for(i=1; i<=m; i++) {
for(j=1; j<=n; j++) {
q******u
发帖数: 46
20
来自主题: JobHunting版 - 算法:按照字典序求第k个排列数
可以算出第一位是floor((k-1)/(n-1)!)+1,剩余的递归就好了。非递归的程序如下:
void print_comb_kth(int n, int k){
int fac = 1;
int i, j;
int *buf;
for (i=2; i<=n; i++) fac*=i;
if (k>fac || k<1){
printf("Index out of range!\n");
return;
}

if (n==1){
printf("1\n");
return;
}
buf = (int*) malloc(sizeof(int)*n);

for (i=1; i<=n; i++) buf[i-1] = i;
for (i=1; i fac /= (n+1-i);
printf("%d", buf[(k-1)/fac]);
j = (k-1)/fac;
while (j buf[j] = buf[j+1];
a**********s
发帖数: 588
21
来自主题: JobHunting版 - 问一个coding的skill
一个方法是弄两个array, CurrentIndices[N], Sizes[N];
memset(CurrentIndices, 0, sizeof(CurrentIndices));
Sizes = {v1.size(), ..., vN.size()};
do {
....
} while(Next(CurrentIndices, Sizes, N));
bool Next(int CurrentIndices[], int Sizes[], int cnt)
{
int i = 0;
while (i < cnt && CurrentIndices[i] == Sizes[i]-1)
CurrentIndices[i++] = 0;
if (i == cnt)
return false;
CurrentIndices[i]++;
return true;
}
没有验证过, 不过我觉得这样也不怎么好
k*k
发帖数: 49
22
来自主题: JobHunting版 - 微软面试题一道
@geniusxsy; thanks,
//my dp solution.
int isInterleavingdp(char* a, char* b, char* str, int alen, int blen){
int i, j;
int m[alen+1][blen+1];
memset(m, 0, (alen+1)*(blen+1)*sizeof(int));

for(i=0; i if (a[i]==str[i])
m[i+1][0]=1;
else
break;
}
for(j=0; j if (b[j] == str[j])
m[0][j+1]=1;
else
break;
}
for(i=1; i<=alen; i++){
for(j=1; j<=blen; j++){
int r1 = (m[i-1][j]>0) && a[i-1]==str[i+j-1];
int r2
c*********t
发帖数: 2921
23
来自主题: JobHunting版 - 给大家看几道C 小程序
就是写出printf的输出结果。
假设这些代码运行在intel cpu, 32bit.
integer 四个bytes.
如果能在十分钟内把这些题都做对,(前提:不去看书,不在计算机上运行),肯定是
对C很熟的。
我今天面试被问到对C 的了解程度,我说 level 10,就被给了这些题,做完后回家才发
现错了很多。感觉很羞愧。
//test1
#include
int main()
{
int i=3;
int j;
j=sizeof(++i + ++i);
printf("i= %d j= %d \n", i, j);
}
c*********t
发帖数: 2921
24
来自主题: JobHunting版 - 给大家看几道C 小程序
sizeof()不算operand的值,只看类型type.
所以i的值仍是 3.
a******n
发帖数: 164
25
来自主题: JobHunting版 - 一道面试题
I also think circular buffer would be a solution:
struct DataSet
{
int nNumberOfEntries;
int iStart;
int iEnd;
uint32_t uKey;
Msg msgSet[MAX_NUMBER]; //MAX_NUMBER can be calculated
//by using max msg rate
float fpTotalSum;
};
void AddMessage(Msg *pMsg)
{
pMsg->m_nKey = uKey++;
memcpy(msgSet + iEnd++, pMsg, sizeof(Msg));

fpTotalSum += pMsg->value;
//check the head of the buffer, to make iStart
//points to Msg that it's still valid,
//and
c****p
发帖数: 32
26
来自主题: JobHunting版 - 问个C++重新编译的问题
嗯,但是也可以从另一个方面来说不需要recompile.

如果已经explicitly 有了其他ctor,加入新的没有影响。
这个基本上是要重新compile,一个例外是加入原来的class本来就只是method的封装比
如:
class Methods
{
public:
staic void test1();
}
这样加入new member fields也没什么关系(但是如果client code有类似sizeof(
Methods)的就不行)
这个一定要重新compile.其他的例子都可以找到反例(虽然有点急转弯的意思),但是
因为dtor是一定要被用到的,如果原本的dtor变成virtual,那么client端整个调用过
程就变了。原来是:
$Class_Dtor();
变成virtual后变成了
pClass->vtbl[index_of_dtor]();
所以client端必须重新compile.
反例是如果这个member function根本就没用到:D
g*******y
发帖数: 1930
27
来自主题: JobHunting版 - onsite完,攒rp系列(二)
上次好像讨论过这个OF的检测吧
就是先知道一个MAX_INT = ~(1< 然后每次做 result = result*10 + digit 之前,判断一下result vs MAX_INT/10, 如
果相等在判断一下 digit vs MAX_INI%10
前面两个方法就比较弱了,一个是OF后会变成负数(这个题目倒是可以用,但不是很好
的方法),一个是用long来保存结果。
P**********0
发帖数: 412
28
来自主题: JobHunting版 - onsite完,攒rp系列(二)
cong and super bless
另外,
1< 是不是已经越界了?
弱弱的问
l**n
发帖数: 88
29
来自主题: JobHunting版 - onsite完,攒rp系列(二)
I think it is 1<<(sizeof(int)*8-1)
m*****f
发帖数: 1243
30
来自主题: JobHunting版 - 一道 C++ 的题。
What about this answer?
class Array{
Array(int);
}
Array *a;
a = (Array *)malloc(sizeof(Array) * 500);
g*******y
发帖数: 1930
31
来自主题: JobHunting版 - 一道 C++ 的题。
T *pArray = (T*) operator new[](500*sizeof(T));
uninitialized_fill(pArray, pArray+500, int);
a****n
发帖数: 1887
32
来自主题: JobHunting版 - 一道 C++ 的题。
very nice solution~
//my solution:
//create: using placement new
A* pa = static_cast (malloc(sizeof(A)*500));
A* pn = pa;
for (int i = 0; i < 500; ++i)
{
pn = new(pn) A(i);
++pn;
}
//destroy: explicit invoke destructor
pn =pa;
for (int i = 0; i < 500; ++i)pn++->~A();
free(pa);
a****n
发帖数: 1887
33
来自主题: JobHunting版 - 一道 C++ 的题。
我是说只用下面这个malloc的情况。。。。。。。。。。。。。。。。。
A* pBuffer = (A*)malloc(sizeof(A)*500);

just
b****g
发帖数: 625
34
来自主题: JobHunting版 - another C interview question
Suppose there is a platform where
sizeof(unsigned int) == 4
and the function app():
unsigned int app(unsigned int)
yields the following output:
app(0x80000000) == 1;
app(0x40000000) == 2;
app(3) == 0xc0000000;
app(0x70) == 0xe000000;
app(0x99999999) == 0x99999999
app(0xAAAAAAAA) == 0x55555555
app(app(x)) == x for all x.
Write a version of app()
k*k
发帖数: 49
35
来自主题: JobHunting版 - 有疑问的一题
some thoughts...
build tree bottom up. nlogn tree construction.
(7) (3) (4) (1) (2) (6) (5) (8)
1) traverse:
merge adj element to produce
(7) (3,4) (1,2) (6,5) (8)
2) traverse again:
(7) (3,4,1,2) (6,5) (8)
3) traverse again
(7) (3,4,1,2,6,5) (8)
4) again
(7, 3, 4, 1, 2, 6, 5) (8)
5) again
(7, 3, 4, 1, 2, 6, 5, 8)
two adj. blocks merge if max(max(Block1), max(Block2)) - min(min(Block1), min(Block2)) == sizeof(block1 + block2)
h**k
发帖数: 3368
36
来自主题: JobHunting版 - 有疑问的一题
how about the case
(3) (5) (1, 2) (6) (4)
Could your algorithm to get the valid block (3,5,1,2,6,4)?

min(Block2)) == sizeof(block1 + block2)
k*k
发帖数: 49
37
来自主题: JobHunting版 - 有疑问的一题
(3) (5) (1, 2) (6) (4)
(3) (5) failed
(5) (1,2) failed
(1,2) (6) failed
(6) (4) failed
(3) (5) (1, 2) failed
(5) (1,2) (6) failed
(1,2) (6) (4) failed
(3) (5) (1, 2) (6) (4)
k adj blocks can merge if
max(max(block 1...k)) - min(min(block 1...k)) == sizeof(block 1...k)
the case u give... may be one of the worst case scenario...
it is similar to the case that all nodes in the tree lines up as a straight
line, so the insertion will take n instead of log n then the complexity
becomes n^2
b****r
发帖数: 1272
38
来自主题: JobHunting版 - how to reverse the bits of an integer?
unsigned int s = sizeof(v) * CHAR_BIT; // bit size; must be power of 2
unsigned int mask = ~0;
while ((s >>= 1) > 0)
{
mask ^= (mask << s);
v = ((v >> s) & mask) | ((v << s) & ~mask);
}
from Bit Twiddling Hacks
g*******y
发帖数: 1930
39
来自主题: JobHunting版 - 问一道书上看到的题
... >>= sizeof(...)*8
g*******y
发帖数: 1930
40
来自主题: JobHunting版 - 问一道书上看到的题
k = k>>sizeof(k)*8
还不明白的话,你得回去补补基础知识了。
f****4
发帖数: 1359
41
来自主题: JobHunting版 - bloomberg电面,攒rp求bless
第一轮的电面,面了80mins
问题:
*你记得你申请的是什么职位么
financial software developer,entry level
*why bloomberg
*多线程系统和多任务系统有啥区别
-线程间通信有哪些方式
-server和client怎么用socket通信
-不用在network里面使用,socket还能用在那些地方
*c++
-virtual function是做什么用的
-polymorphism是怎么实现的,virtual table, virtual table pointer是怎么帮助
polymorphism实现的;用静态type和动态type来解释polymorphism的绑定
-给一个实际的设计必须要用到polymorphism的
-class student; student *p = new student; memset(p, 0, sizeof(student));这
个memset有问题么,实现什么功能
*program,输入一个long double,格式化后输出。例如: 234567614.98
h**6
发帖数: 4160
42
来自主题: JobHunting版 - 请教1个工作面试题
还有,分配内存的时候sizeof的结果是写死在二进制文件里的,需要重新编译改为8字
节。
r****o
发帖数: 1950
43
来自主题: JobHunting版 - 问个bit struct的面试题 急
恩,好像用unsigned int占用空间更大。
问一下,怎么看一个struct 占用了多少bit啊?用sizeof()好像只能看byte。
多谢。
f****4
发帖数: 1359
44
int bitCounter(int number){
int counter = 0;
int n = sizeof(int) * 8;
int mask = 1 << (n - 1);
for(int i = 1; i <= n; ++i)
{
if((mask & number) != 0)
++counter;
number <<= 1;
}
return counter;
}
只能做<<操作,如果是负数,>>会有1多出来的
y**i
发帖数: 1112
45
来自主题: JobHunting版 - 请教一道面试题
我刚写了一个,不知道有没有什么地方可以优化的,感兴趣的可以看一下,我们可以讨
论一下,也让我学习一下,谢谢了!
// Find minimum number of coins to get the exact amount
int FindCoins(int demon[], int nd, int amount)
{
int* N = new int[nd]; // save the number of each coins
memset(N, 0, nd*sizeof(int));
int n = 0, sum = 0;
while (sum != amount)
{
if (sum < amount) // continue to add current denomination
{
sum += demon[n];
++N[n];
}
else // back-track to subtract current coins
{
while
f*******5
发帖数: 52
46
来自主题: JobHunting版 - bloomberg电面
刚面完,印度人面的,口音能听懂。先问了做过的project。
然后进入technical环节,问了static是啥意思,然后问如果有两个全局变量i,j,i是
static,j
不是,i和j有啥区别。我说没区别,这两个到底有什么区别?
然后问了process和thread的区别,这个我不知道,冷场半天,后来回答得把自己绕晕
了。
然后问malloc有没有可能没申请到内存,什么情况下没申请到。我回答memory leak,
然后让我解释
memory leak。
然后让我用malloc申请一个100元素的int数组,问为啥sizeof(int)不直接写4.
然后问我都用过什么data structure,问hashtable用过没有,我说没有。然后问我
binary tree
和binary search tree区别。问binary search tree有重复怎么办,比如13445的
binary
search tree是什么,我说直接drop duplicate。search 复杂度是多少,平均和最坏情
况下。
最后让我问个问题,我问结果啥时候告我,他说一周。最后这个问问题阶段应该问
l**3
发帖数: 45
47
来自主题: JobHunting版 - bloomberg onsite
出租车很不错,不过bloomberg只定了从机场到bloomberg的taxi。回到机场的出租车要
自己出钱。不过bloomberg给了100刀的gift card cover路上的费用。看来还是很有钱
的。
中午12点到下午2点,在传说中的玻璃会议室里面试。没有签NDA,那我就透露一下题目
吧。
先是两个小印面试,问了以往的project,然后问了以下技术问题。
程序找错
void my_malloc (void * ptr, int size) { ------> ptr should be int**
ptr = malloc(size); -----------> *ptr = (int *)malloc(size*sizeof(int))
}
int main () {
int * ptr;
int i;
my_malloc(ptr, 10); ------------> my_malloc(&ptr, 10);
s**9
发帖数: 207
48
来自主题: JobHunting版 - bloomberg onsite
bless
第一题还有一个改法:
void my_alloc(void * & ptr, int size)

sizeof(int))
f****4
发帖数: 1359
49
来自主题: JobHunting版 - Placement new的一个问题
void *p = malloc(sizeof(CopyCtr));
CopyCtr *pCC = new (p) CopyCtr(10);
// ..................
pCC->~CopyCtr(); // call destructor ONLY ONLY with placement New
free(p);
这个是很标准的Placement new的用法,CopyCtr是一个test class
我的问题是,如果这个CopyCtr,没有额外申请任何heap资源的话(就是所有
datamember都是内置类型,这个class也不是自己counting reference 的class),那
么不call
pCC->~CopyCtr() 而直接free p。有啥危害没有?
这个不是面试题,就是复习的时候想到的;大家有啥建议没?
我只能想到这个 不规范,还有别的么?
f****4
发帖数: 1359
50
来自主题: JobHunting版 - 一道linked list编程题
更简单的版本
Node* insertInOrder(Node *head, int value){
Node *curr,*prev=NULL,*temp,
*newNode=static_cast( malloc(sizeof(Node)));
newNode->data=value;newNode->next=NULL;
if(head==NULL)
return newNode;

curr=head;
while(curr!=NULL&&curr->data prev=curr;
curr=curr->next;
}

if(prev==NULL){
newNode->next=head;
return newNode;
}
else
if(curr==NULL)
prev->next=newNode;
el
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)