1.whats the value of x.
x = 20;
y=30;
x=y++ + x++;
x = 30++ + 20 ++ = 50 but there is one ++ pending for x which shall be executed so the value of x will 51 .
2.write a function to check its a big endian or little endian
first method
union test{
int i;
char c;
};
test t1;
t1.i = 1;
if(t1.c == 1){
pf("LE");
}
else
pf("BE");
second method.
int i=1;
if( *(char*)&i == 1)
pf("LE");
else
pf("BE")
3.write a program to reverse the bits in an integer 1101 ==> 1011
int output;
for(int i=0;i<32;i++){
if( input & 1 ==1 ){
output |= 1<<32-i;
}
input = input >> 1;
}
4.
int inc(int ip){
static int i=2;
i += ip;
return i;
}
x = 10;
if( inc(x) == 12 || inc(x) == 14 )
pf("%d",inc(10)) ;
whats is the output? its quite easy .. let me know if u need answer.
5.Think about the reason for one thread not receiving the message by the other thread .
6.write a function to reverse the linked list.
check page 33 and 34 of this article
7.If we have 2 set of identical numbers and if we zero down any one of the number, find that number
one easy solution would be get the sum of both the set and the difference will give you the answer.(can be done in O(n) )
second solution is sort both of the arrays and compare them at each position (but sort them in ascending order or descending order ? Think :) )
8. let say we have 3 macros to print something like below
1 #define PRINT3(b1,b2,b3) /
myprint("%x %x %x",b1,b2,b3);
2 #define PRINT2(b1,b2) /
myprint("%x %x",b1,b2);
3 #define PRINT1(b1) /
myprint("%x",b1);
write a function which receives length i.e total number of bits and char* actual data to print each bit using above macros, make as small as possible and working.
pseudo code
while(len>0)
{
if(len>3){
// use PRINT3
len = len-3;
}
else if(len == 2){
// use PRINT2
len = len-2;
}
else{
//use PRINT1
len = len-1;
}
}
9.Write diff kind of functions to multiply by 7.
int mul71(int i){
return i*7;
}
int mul72(int i){
int pr = 0;
for(i = 0;i <min(i,7);i++)
pr += max(i,7);
return pr;
}
int mul73(int i)
{
return i<<3 - i;
}
10. what is re-entrant function ?
x = 20;
y=30;
x=y++ + x++;
x = 30++ + 20 ++ = 50 but there is one ++ pending for x which shall be executed so the value of x will 51 .
2.write a function to check its a big endian or little endian
first method
union test{
int i;
char c;
};
test t1;
t1.i = 1;
if(t1.c == 1){
pf("LE");
}
else
pf("BE");
second method.
int i=1;
if( *(char*)&i == 1)
pf("LE");
else
pf("BE")
3.write a program to reverse the bits in an integer 1101 ==> 1011
int output;
for(int i=0;i<32;i++){
if( input & 1 ==1 ){
output |= 1<<32-i;
}
input = input >> 1;
}
4.
int inc(int ip){
static int i=2;
i += ip;
return i;
}
x = 10;
if( inc(x) == 12 || inc(x) == 14 )
pf("%d",inc(10)) ;
whats is the output? its quite easy .. let me know if u need answer.
5.Think about the reason for one thread not receiving the message by the other thread .
- meomry corruption
- other thread reading message for this tread
- if they are using queue, queue might be full
- if the receiving thread is of low priority and it never getting chance to execute and hence cant read the msg.
6.write a function to reverse the linked list.
check page 33 and 34 of this article
7.If we have 2 set of identical numbers and if we zero down any one of the number, find that number
one easy solution would be get the sum of both the set and the difference will give you the answer.(can be done in O(n) )
second solution is sort both of the arrays and compare them at each position (but sort them in ascending order or descending order ? Think :) )
8. let say we have 3 macros to print something like below
1 #define PRINT3(b1,b2,b3) /
myprint("%x %x %x",b1,b2,b3);
2 #define PRINT2(b1,b2) /
myprint("%x %x",b1,b2);
3 #define PRINT1(b1) /
myprint("%x",b1);
write a function which receives length i.e total number of bits and char* actual data to print each bit using above macros, make as small as possible and working.
pseudo code
while(len>0)
{
if(len>3){
// use PRINT3
len = len-3;
}
else if(len == 2){
// use PRINT2
len = len-2;
}
else{
//use PRINT1
len = len-1;
}
}
9.Write diff kind of functions to multiply by 7.
int mul71(int i){
return i*7;
}
int mul72(int i){
int pr = 0;
for(i = 0;i <min(i,7);i++)
pr += max(i,7);
return pr;
}
int mul73(int i)
{
return i<<3 - i;
}
10. what is re-entrant function ?
Comments
Post a Comment