C++ Interview Questions (to be modified...)

1.      Will the following program execute?void main()
{
void *vptr = (void *) malloc(sizeof(void));
vptr++;
}

Compile error. Cannot convert from int to char*.

 

2.      How about this one?
void main()
{
char *cptr = 0X2000;
long *lptr = 0X2000;
cptr++;
lptr++;
printf(” %x %x”, cptr, lptr);
}Will it execute or not?

Compile error as the sizeof operator cannot be used with void. And we cannot get the size of size of void*, so vptr++ also produce compile error.

 

3.      When the processor wakes up after power on, it goes to a particular memory location. What is that memory location called?

Wossit got to do with C++?

 

processor goes to MBR (master boot record) then i takes the address of boot loader form thr and execute this boot loader program

 

4.      What is the difference between Mutex and Binary semaphore?

From Multithreaded Applications in Win32, by Jim Beveridge ( page 93 ):
“…it turns out that a mutex is a degenerated form of a semaphore. If you create a semaphore and set the maximum count to one, you get mutual exclusion behavior. therefore a mutex is often refered to as a binary semaphore…In Win32, the ownership semantics of how the two operate are quite different, so they cannot be used interchangeably…”

 

Mutex is efficent than semaphore. Also unlocking of mutex can be done by the thread which owns the lock. Not the case with semaphore.

 

5.      Write a program to set 2nd bit in a 32 bit register with memory location 0×2000?

By “2nd bit” are you counting from most significant or least significant bit? Anyway, the answer is platform-dependent and compiler-dependent. Assuming you have a typedef “uint32″ that is exactly 32 bits long, then try something like *reinterpret_cast(0×2000) = 0×40000000 (for 2nd msb) or = 2 (for 2nd lsb)

 

6.

void main()

{

printf("%d/n");

printf("%d %d/n");

printf("%d %d %d/n");

}

Output:

0

0 309590428

0 309590428 2147348480

 

Why this?

 

7.

void main()

{

int *p = 0;//0 is NULL

delete p;

}

NO error and warning.

 

P.S. What’s the differences between critical section and mutex?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值