android-porting USB mtp
1 vold.conf
2. init.rc setprop persist.service.mount.umsauto 1
2009年10月22日 星期四
2009年10月8日 星期四
2009年10月6日 星期二
贴上答案作参考--嵌入式研发工程师面试试题大全(ANSI C/C++方面的知识)
贴上答案作参考--嵌入式研发工程师面试试题大全(ANSI C/C++方面的知识)402674129 2008-3-15 19:35:48 收藏 | 打印 | 投票(15) | 评论(15) | 阅读(86153) ◇字体:[大 中 小] 看了一篇叫“嵌入式研发工程师面试试题大全”的文章,觉得里面的题目很有水平,我会分阶段做完这些题目,并贴出来接受大家的指正。今天先贴上“ANSI C/C++方面的知识 ”,有不妥之处希望博友能给出意见,而且有几道本人尚不清楚,需要大家帮助解决。
一.ANSI C/C++方面的知识
1、简答题。
1、 如何在C中初始化一个字符数组。
逐个字符赋值:char s[] = {‘A’,’B’,’C’,’D’};
字符串赋值:char s[] = {“ABCD”};
对于二维字符数组:char s[2][10] = {“cheng”,”jinzhou”};
2、 如何在C中为一个数组分配空间。
如果是栈的形式,Type s[N]定义后系统自动分配空间,分配的空间大小受操作系统限制;
若是堆的形式,Type *s; s = (Type *)malloc(sizeof(Type) * N); 分配的空间大小不受操作系统限制。
3、 如何初始化一个指针数组。
这里有必要重新对比一下指针数组与数组指针的差异。
a. 指针数组:数组里存储的是指针。
如:int * s[ 5 ] 表示数组s里存储了5个指向整型的指针。
Char * s[ 3 ] = {“aaaaa”,”bbb”,”ccccc”} 表示数组s里存储3个指向字符型的指针,分别指向字符串aaaaa、bbb、ccccc。
b. 数组指针:其实就是数组,里面存放的是数据。
如:int ( * s )[ 5 ] 表示数组s里存储了5个整型数据。
4、 如何定义一个有10个元素的整数型指针数组。
Int * s [ 10 ];
5、 s[10]的另外一种表达方式是什么。
* ( s + 10 )
二维数组S [ 5 ][ 8 ]的表示方法:*( *(s + 5) + 8 )
7、 要使用CHAR_BIT需要包含哪个头文件。
Include limits.h
在该头文件里 #define CHAR_BIT 8
8、 对(-1.2345)取整是多少? -1
9、 如何让局部变量具有全局生命期。
使用Static,局部变量就存储在全局区(静态区),便具有全局的生命期和局部的访问控制。
10、C中的常量字符串应在何时定义?
没有理解到题目的意思,我只是想说明一点,定义常量字符串后它属于const型,不能去修改它,否则程序出错。
11、如何在两个.c文件中引用对方的变量。
使用extern
12、使用malloc之前需要做什么准备工作。
定义一个指针后就可以malloc了。
13、realloc函数在使用上要注意什么问题。
Realloc后返回的指针与之前malloc返回的指针指向的地址不同。
14、strtok函数在使用上要注意什么问题。
首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL
15、gets函数在使用上要注意什么问题。
这里要将Scanf( )、gets( )放在一起比较。Scanf( )是遇到空格就判断为输入结束,而gets( )则遇到回车才判断为输入结束。
16、C语言的词法分析在长度规则方面采用的是什么策略?
尚不清楚,望博友能告知,万分感谢!
17、a+++++b所表示的是什么意思?有什么问题?
根据自增运算符的右结合性,它是(a++)+(++b)的意思,但有的编译器里省略括号就不能通过,同时也降低了程序可读性。
18、如何定义Bool变量的TRUE和FALSE的值。
#define TRUE 1
#define FALSE 0
19、C语言的const的含义是什么。在定义常量时,为什么推荐使用const,而不是#define。
Const是只读的意思,它限定一个变量不允许被改变。
#define缺乏类型检测机制,在预处理时候有可能引发错误。
Const方面的其它知识扩展:
问题1:const变量 & const 限定的内容
下面的代码编译器会报一个错误,请问,哪一个语句是错误的呢?
typedef char * pStr;
char string[4] = "abc";
const char *p1 = string; // *p1 作为整体不能被修改,但p1可以修改,p1++合法
const pStr p2 = string; //p2作为一个整体,不能被修改,但是下面的p2++非法修改
p1++;
p2++;
问题2:const变量 & 字符串常量
请问下面的代码有什么问题?
char *p = "i''''''''m hungry!"; //定义的是字符串常量
p[0]= ''''''''I'''' //不能修改字符串常量
问题:const变量 & 字符串常量2
char a[3] = "abc" 合法吗?使用它有什么隐患?
没有考虑到字符串结束符‘\0’,所以会产生意想不到的错误。
比如以下程序:
int main()
{
int i;
char p[6] = {''''''''a'''''''',''''''''b'''''''',''''''''c'''''''',''''''''d'''''''',''''''''e'''''''',''''''''f''''''''};
printf("%s",p);
while(1);
return 0;
}
运行后显示: abcdef@
问题3:const & 指针
类型声明中const用来修饰一个常量,有如下两种写法,那么,请问,下面分别用const限定不可变的内容是什么?
1)、const在前面
a. const int nValue; //nValue是const
把类型int撇开,变量nValue作为一个整体,因此 nValue是const型;
b. const char *pContent; //*pContent是const, pContent可变
把类型char撇开,变量 *pContent作为一个整体,因此 *pContent是const型;
c. const (char *) pContent;//pContent是const,*pContent可变
把类型char * 撇开,注意这里(char * )是一个整体,而变量 pContent作为一个整体,因此 pContent是const型;
d. char* const pContent; //pContent是const,*pContent可变
const与变量间没有类型,变量 pContent作为一个整体,因此 pContent是const型;
e. const char* const pContent; //pContent和*pContent都是const
这里分为两层,外层:把类型char 撇开,变量 * const pContent作为一个整体,因此 * pContent是const型;内层:没有类型,因此 pContent 是 const 型。
2)、const在后面,与上面的声明对等 (这类型更容易判断)
a. int const nValue; // nValue是const
const与变量之间没有类型,const后面那部分整体是const型,因此nValue是const型
b. char const * pContent;// *pContent是const, pContent可变
const与变量之间没有类型,const后面那部分整体是const型,因此 * pContent是const型
c. (char *) const pContent;//pContent是const,*pContent可变
const与变量之间没有类型,const后面那部分整体是const型,因此 pContent是const型
d. char* const pContent;// pContent是const,*pContent可变
const与变量之间没有类型,const后面那部分整体是const型,因此 pContent是const型
e. char const* const pContent;// pContent和*pContent都是const
分为两层,外层:撇开类型char,const后面那部分整体* const pContent是const型,因此 * pContent是const型;内层:const与pContent之间无类型,因此pContent是const型。
C++中CONST
C中常用:#define 变量名 变量值定义一个值替代,然而却有个致命缺点:缺乏类型检测机制,这样预处理理在C++中成为可能引发错误的隐患,于是引入const.
const使用:
1. 用于指针的两种情况:const是一个左结合的类型修饰符.
int const *A; //A可变,*A不可变
int *const A; //A不可变,*A可变
2.限定函数的传递值参数:
void function(const int Var); //传递过来的参数在函数内不可以改变.
3.限定函数返回值型.
const int function(); //此时const无意义
const myclassname function(); //函数返回自定义类型myclassname.
20、C语言的volatile的含义是什么。使用时会对编译器有什么暗示。
volatile的本意是“易变的”
由于访问寄存器的速度要快过RAM,所以编译器一般都会作减少存取外部RAM的优化,但有可能会读脏数据。当要求使用volatile 声明的变量的值的时候,系统总是重新从它所在的内存读取数据,即使它前面的指令刚刚从该处读取过数据。而且读取的数据立刻被保存。
精确地说就是,优化器在用到这个变量时必须每次都小心地重新读取这个变量的值,而不是使用保存在寄存器里的备份。
下面是volatile变量的几个例子:
1). 并行设备的硬件寄存器(如:状态寄存器)
2). 一个中断服务子程序中会访问到的非自动变量(Non-automatic variables)
3). 多线程应用中被几个任务共享的变量
嵌入式系统程序员经常同硬件、中断、RTOS等等打交道,所用这些都要求volatile变量。不懂得volatile内容将会带来灾难。
Volatile的完全扩展:
1). 一个参数既可以是const还可以是volatile吗?解释为什么。
是的。一个例子是只读的状态寄存器。它是volatile因为它可能被意想不到地改变。它是const因为程序不应该试图去修改它。
2). 一个指针可以是volatile 吗?解释为什么。
是的。尽管这并不很常见。一个例子是当一个中服务子程序修该一个指向一个buffer的指针时。
3). 下面的函数有什么错误:
int square(volatile int *ptr)
{
return *ptr * *ptr;
}
这段代码的有个恶作剧。这段代码的目的是用来返指针*ptr指向值的平方,但是,由于*ptr指向一个volatile型参数,编译器将产生类似下面的代码:
int square(volatile int *ptr)
{
int a,b;
a = *ptr;
b = *ptr;
return a * b;
}
由于*ptr的值可能被意想不到地该变,因此a和b可能是不同的。结果,这段代码可能返不是你所期望的平方值!正确的代码如下:
long square(volatile int *ptr)
{
int a;
a = *ptr;
return a * a;
}
一.ANSI C/C++方面的知识
1、简答题。
1、 如何在C中初始化一个字符数组。
逐个字符赋值:char s[] = {‘A’,’B’,’C’,’D’};
字符串赋值:char s[] = {“ABCD”};
对于二维字符数组:char s[2][10] = {“cheng”,”jinzhou”};
2、 如何在C中为一个数组分配空间。
如果是栈的形式,Type s[N]定义后系统自动分配空间,分配的空间大小受操作系统限制;
若是堆的形式,Type *s; s = (Type *)malloc(sizeof(Type) * N); 分配的空间大小不受操作系统限制。
3、 如何初始化一个指针数组。
这里有必要重新对比一下指针数组与数组指针的差异。
a. 指针数组:数组里存储的是指针。
如:int * s[ 5 ] 表示数组s里存储了5个指向整型的指针。
Char * s[ 3 ] = {“aaaaa”,”bbb”,”ccccc”} 表示数组s里存储3个指向字符型的指针,分别指向字符串aaaaa、bbb、ccccc。
b. 数组指针:其实就是数组,里面存放的是数据。
如:int ( * s )[ 5 ] 表示数组s里存储了5个整型数据。
4、 如何定义一个有10个元素的整数型指针数组。
Int * s [ 10 ];
5、 s[10]的另外一种表达方式是什么。
* ( s + 10 )
二维数组S [ 5 ][ 8 ]的表示方法:*( *(s + 5) + 8 )
7、 要使用CHAR_BIT需要包含哪个头文件。
Include limits.h
在该头文件里 #define CHAR_BIT 8
8、 对(-1.2345)取整是多少? -1
9、 如何让局部变量具有全局生命期。
使用Static,局部变量就存储在全局区(静态区),便具有全局的生命期和局部的访问控制。
10、C中的常量字符串应在何时定义?
没有理解到题目的意思,我只是想说明一点,定义常量字符串后它属于const型,不能去修改它,否则程序出错。
11、如何在两个.c文件中引用对方的变量。
使用extern
12、使用malloc之前需要做什么准备工作。
定义一个指针后就可以malloc了。
13、realloc函数在使用上要注意什么问题。
Realloc后返回的指针与之前malloc返回的指针指向的地址不同。
14、strtok函数在使用上要注意什么问题。
首次调用时,s必须指向要分解的字符串,随后调用要把s设成NULL
15、gets函数在使用上要注意什么问题。
这里要将Scanf( )、gets( )放在一起比较。Scanf( )是遇到空格就判断为输入结束,而gets( )则遇到回车才判断为输入结束。
16、C语言的词法分析在长度规则方面采用的是什么策略?
尚不清楚,望博友能告知,万分感谢!
17、a+++++b所表示的是什么意思?有什么问题?
根据自增运算符的右结合性,它是(a++)+(++b)的意思,但有的编译器里省略括号就不能通过,同时也降低了程序可读性。
18、如何定义Bool变量的TRUE和FALSE的值。
#define TRUE 1
#define FALSE 0
19、C语言的const的含义是什么。在定义常量时,为什么推荐使用const,而不是#define。
Const是只读的意思,它限定一个变量不允许被改变。
#define缺乏类型检测机制,在预处理时候有可能引发错误。
Const方面的其它知识扩展:
问题1:const变量 & const 限定的内容
下面的代码编译器会报一个错误,请问,哪一个语句是错误的呢?
typedef char * pStr;
char string[4] = "abc";
const char *p1 = string; // *p1 作为整体不能被修改,但p1可以修改,p1++合法
const pStr p2 = string; //p2作为一个整体,不能被修改,但是下面的p2++非法修改
p1++;
p2++;
问题2:const变量 & 字符串常量
请问下面的代码有什么问题?
char *p = "i''''''''m hungry!"; //定义的是字符串常量
p[0]= ''''''''I'''' //不能修改字符串常量
问题:const变量 & 字符串常量2
char a[3] = "abc" 合法吗?使用它有什么隐患?
没有考虑到字符串结束符‘\0’,所以会产生意想不到的错误。
比如以下程序:
int main()
{
int i;
char p[6] = {''''''''a'''''''',''''''''b'''''''',''''''''c'''''''',''''''''d'''''''',''''''''e'''''''',''''''''f''''''''};
printf("%s",p);
while(1);
return 0;
}
运行后显示: abcdef@
问题3:const & 指针
类型声明中const用来修饰一个常量,有如下两种写法,那么,请问,下面分别用const限定不可变的内容是什么?
1)、const在前面
a. const int nValue; //nValue是const
把类型int撇开,变量nValue作为一个整体,因此 nValue是const型;
b. const char *pContent; //*pContent是const, pContent可变
把类型char撇开,变量 *pContent作为一个整体,因此 *pContent是const型;
c. const (char *) pContent;//pContent是const,*pContent可变
把类型char * 撇开,注意这里(char * )是一个整体,而变量 pContent作为一个整体,因此 pContent是const型;
d. char* const pContent; //pContent是const,*pContent可变
const与变量间没有类型,变量 pContent作为一个整体,因此 pContent是const型;
e. const char* const pContent; //pContent和*pContent都是const
这里分为两层,外层:把类型char 撇开,变量 * const pContent作为一个整体,因此 * pContent是const型;内层:没有类型,因此 pContent 是 const 型。
2)、const在后面,与上面的声明对等 (这类型更容易判断)
a. int const nValue; // nValue是const
const与变量之间没有类型,const后面那部分整体是const型,因此nValue是const型
b. char const * pContent;// *pContent是const, pContent可变
const与变量之间没有类型,const后面那部分整体是const型,因此 * pContent是const型
c. (char *) const pContent;//pContent是const,*pContent可变
const与变量之间没有类型,const后面那部分整体是const型,因此 pContent是const型
d. char* const pContent;// pContent是const,*pContent可变
const与变量之间没有类型,const后面那部分整体是const型,因此 pContent是const型
e. char const* const pContent;// pContent和*pContent都是const
分为两层,外层:撇开类型char,const后面那部分整体* const pContent是const型,因此 * pContent是const型;内层:const与pContent之间无类型,因此pContent是const型。
C++中CONST
C中常用:#define 变量名 变量值定义一个值替代,然而却有个致命缺点:缺乏类型检测机制,这样预处理理在C++中成为可能引发错误的隐患,于是引入const.
const使用:
1. 用于指针的两种情况:const是一个左结合的类型修饰符.
int const *A; //A可变,*A不可变
int *const A; //A不可变,*A可变
2.限定函数的传递值参数:
void function(const int Var); //传递过来的参数在函数内不可以改变.
3.限定函数返回值型.
const int function(); //此时const无意义
const myclassname function(); //函数返回自定义类型myclassname.
20、C语言的volatile的含义是什么。使用时会对编译器有什么暗示。
volatile的本意是“易变的”
由于访问寄存器的速度要快过RAM,所以编译器一般都会作减少存取外部RAM的优化,但有可能会读脏数据。当要求使用volatile 声明的变量的值的时候,系统总是重新从它所在的内存读取数据,即使它前面的指令刚刚从该处读取过数据。而且读取的数据立刻被保存。
精确地说就是,优化器在用到这个变量时必须每次都小心地重新读取这个变量的值,而不是使用保存在寄存器里的备份。
下面是volatile变量的几个例子:
1). 并行设备的硬件寄存器(如:状态寄存器)
2). 一个中断服务子程序中会访问到的非自动变量(Non-automatic variables)
3). 多线程应用中被几个任务共享的变量
嵌入式系统程序员经常同硬件、中断、RTOS等等打交道,所用这些都要求volatile变量。不懂得volatile内容将会带来灾难。
Volatile的完全扩展:
1). 一个参数既可以是const还可以是volatile吗?解释为什么。
是的。一个例子是只读的状态寄存器。它是volatile因为它可能被意想不到地改变。它是const因为程序不应该试图去修改它。
2). 一个指针可以是volatile 吗?解释为什么。
是的。尽管这并不很常见。一个例子是当一个中服务子程序修该一个指向一个buffer的指针时。
3). 下面的函数有什么错误:
int square(volatile int *ptr)
{
return *ptr * *ptr;
}
这段代码的有个恶作剧。这段代码的目的是用来返指针*ptr指向值的平方,但是,由于*ptr指向一个volatile型参数,编译器将产生类似下面的代码:
int square(volatile int *ptr)
{
int a,b;
a = *ptr;
b = *ptr;
return a * b;
}
由于*ptr的值可能被意想不到地该变,因此a和b可能是不同的。结果,这段代码可能返不是你所期望的平方值!正确的代码如下:
long square(volatile int *ptr)
{
int a;
a = *ptr;
return a * a;
}
2009年10月5日 星期一
Embedded System Interview Questions:
Embedded System Interview Questions:
1. Can structures be passed to the functions by value? 1.結構体是否能传值给函数?
2. Why cannot arrays be passed by values to functions? 2.为什么数组不能传值给函数?
3. Advantages and disadvantages of using macro and inline functions? 3.宏定义和内联函数的利弊是什么?
4. What happens when recursion functions are declared inline? 4.将递归函数定义为内联函数会出现什么情况?
5. Scope of static variables? 5.静态变量的有效范?
6. Difference between object oriented and object based languages? 6.面向对象与面向基础的区别是什么?
7. Multiple inheritance - objects contain how many multiply inherited ancestor? 7.多态继承能包含多少祖先级的多态?
8. What are the 4 different types of inheritance relationship? 8.4种继承关系是什么?
9. How would you find out the no of instance of a class? 9.如何找出无实例类?
10. Is java a pure object oriented language? Why? 10.JAVA是纯面向对象语言吗?为什么?
11. Order of constructor and destructor call in case of multiple inheritance? 11.是否允许再多态种调用构造函数和析构函数?
12. Can u have inline virtual functions in a class? 12.在你的类种是否会含有内联虚函数?
13. When you inherit a class using private keyword which members of base class are visible to the derived class? 13.在什么情况下你继承的私有类种成员是基类的显性成员?
14. What is the output of printf("\nab\bcd\ref"); -> ef 14.printf("\nab\bcd\ref"); 会输出什么?
15. #define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives preprocessor warning. Why? 15.#define cat(x,y) x##y 链接 x to y.但是cat(cat(1,2),3)不能扩展同时会有预处理警告,为什么?
16. Can you have constant volatile variable? Yes, you can have a volatile pointer? 16.是否可以有可变恒常量?如果是是否有可变指针?
17. ++*ip increments what? it increments what ip points to 17++*ip增加了什么?它将IP指向了什么?
18. Operations involving unsigned and signed — unsigned will be converted to signed 18.操作类型包括符号型和非符号型---非符号型会转换成符号型?
19. a+++b -> (a++)+b 19.a+++b->(a++)+b ji
20. malloc(sizeof(0)) will return — valid pointer 20.malloc(sizeof(0)) 将会返回的有效指针
21. main() {fork();fork();fork();printf("hello world"); } — will print 8 times. 21.main() {fork();fork();fork();printf("hello world"); } 会打印8次?
22. Array of pts to functions — void (*fptr[10])() 22.指针数组函数 void (*fptr[10])()
23. Which way of writing infinite loops is more efficient than others? there are 3ways. 23.如何写死循环更有效?
24. # error — what it does? 24.#ERROR是干吗的?
25. How is function itoa() written? 25.如何实现itoa()?
26. Who to know wether system uses big endian or little endian format and how to convert among them? 26.谁去分析系统使用了大系统还是小系统。(大头小头)
Intel的AISC指令都是低字节在前,苹果等Power PC的cpu使用的是RISC指令集,都是高字节在前。如何转变他们?
27. What is interrupt latency? 27.什么是中断响应?
28. What is forward reference w.r.t. pointers in c? 28.什么在C中分析w.r.t. pointers?
29. How is generic list manipulation function written which accepts elements of any kind?
30. What is the difference between hard real-time and soft real-time OS? 30.软实时操作系统和硬实时操作系统的区别?
31. What is interrupt latency? How can you recuce it? 31.什么是中断潜伏?你如何识别它?
32. What is the differnce between embedded systems and the system in which rtos is running? 32.嵌入式操作系统和实时操作系统的区别?
33. How can you define a structure with bit field members? 33.如何定义 bit field members的結構体
34. What are the features different in pSOS and vxWorks? 34.PSOS和VXWORKS功能区别有那些?
35. How do you write a function which takes 2 arguments - a byte and a field in the byte and returns the value of the field in that byte? 35......
36. What are the different storage classes in C? 36.C中的存储类有什么不同?
37. What are the different qualifiers in C? 37.C中有什么不同的限定?
38. What are the different BSD and SVR4 communication mechanisms BSD与SVR4通讯有什么不同?
Persional Prospectives:
1.
Q1. No they are always passed by reference. Think. Size of structure can be arbitrarily large. Q2. Same as above. Q5. Lifetime of process. Q9. Declare a static variable, class variable, and increment(decrement) for every constructor (destructor) called. Q11. Constructor. Base to current. Destructor. current to base. Both are done recursuively. Q13. NONE Q14. $> acd ef ->ef is wrong, what happened to acd? Q16. You can have a constant pointer to a volatile variable but not a constant volatile variable. Q26. Write a union of int and 2 chars. Store as int retrieve as chars. Q 27. Time taken between INT req and INT service. Q33. Study Let us C, Yeshwant Kanetkar
Tech Interviews comment by Taran
2.
Q. 13 Answer posted is wrong. Public & protected members of base class will be visible to derived class, but not its objects.
Tech Interviews comment by Sumeet
3.
Q1 - YES, a complete structure can be passed. Regarding the size, it is true that they can be very large and hence it is not a good practice to do so. In any case, one can do if one wants to.
Tech Interviews comment by Bhaskar
4.
Q3. When using macro you can’t use data type while passing it. But in Inline function you can have data types so that it can be checked. e.g MACRO : ADD(a,b) INLINE : inline void Add(int a,int b );
Tech Interviews comment by VijayaKumar
5.
Q1. Yes structure can be passed by value but the overhead of copying large values will be there. hence not usable. We should pass it by pointer. Q2. Individual element can be passed by value of course. But not whole array. Q5. It is alive lifetime of process, and its scope is limited to function in which it is defined. file1.c ********** static int i; void main() { …….. } file2.c ********** extern int i; //error
If declared global then it is visible in that file only. Q6. Object oriented language have Inheritance, polymorphism etc. But object based language only deal with object. Q7. If class D:public A,B,C {} then three ancestors Q8. public ,private, protected, virtual Q30. Hard RTS is having deadline defined and it is life critical ,should be reliable. late answer is wrong answer. in Soft RTS,process time should be predictable and reliable.
Tech Interviews comment by Pawan Kumar
6.
Q36.What are the different storage classes in C? A:Auto,Register,Static,Extern
Tech Interviews comment by MKS
7.
Q5 Scope of static variables is only within the block where it is declared. But the lifetime is till the process is running
Tech Interviews comment by Satish Parande
8.
Questin???
How can we dynamically allocate memory without using malloc() or calloc() or realloc()?Explain in Breif.
Can any one help in finding this answer to this question……
Tech Interviews comment by Midhun V
9.
In Java, we place even the Main() function inside a CLASS. But it is not the case with C++.
So, i think this is one of the answers you can say, JAVA is Fully Obejct Oriented.
Tech Interviews comment by vsvraju
10.
Q11 : Base-class constructors are called in the order in which inheritance is specified in the derived-class definition. The order in which the Base-class constructors are specified in the derived-class member initializer list does not effect the order of construction.
Tech Interviews comment by vsvraju
11.
Q 12: Yes we can have. you are never guaranteed that a routine is inlined. It is only a suggestion to the compiler. If the routine is either too complicated or a virtual function,then a static copy of the routine will be placed in the compiled module. Thus, a routine that was coded as inline may cause a performance degradation because it may consume much more space when it is not physically inlined. With a virtual function, a copy of that routine will be created for every module that has at least one instantiation of that class.
Q 13: NONE. None of the Public, Protected and Private data members are visible.
Q 16: YES. We can have a const volatile variable. a volatile variable is a variable which can be changed by the extrenal events (like an interrput timers will increment the voltile varible. If you dont want you volatile varibale to be changed then declare them as “const volatile”.
Q 17. I will explain this with an example:
int a = 10; int *p = &a; // suppose &a = 4010 (address of a)
Because both ++ and * are unary operators, the are calculated from right to left –> ++ (*p)
++*p will inrement 4010 by 4 (int size) -> ++*p will have the value 4014.
Q 21: It will print 8 times. Because, each fork will print twice. if u flush, (using “fflush”), then it will be printed only once. thats is you need to flush the iostreams.
Q 30:
In Hard RTOS the latency should be less the 20ns (nano sec) in Soft RTOS the latency range 3ns - 20ns is also acceptable.
Tech Interviews comment by vsvraju
12.
I THINK A BALOON CAN HAVE TO MUCH ELECTRICITY
Tech Interviews comment by SANDRA
13.
Java is not a pure object oriented language as “everything” in java is not an object. It still has primitive data types such as int, char, etc. which are NOT objects. Ruby is an example of a pure object oriented language, where “everything” is an object, even int.
Tech Interviews comment by Karan
14.
16. It is possible to have “const volatile” declaration. This indicates that the variable defined like this is not possible to change within that context. It can be changed by an external event. const declaraion just says that it will be readonly within the context, that area can be modified by an interrupt routine or another process.
18. Operations involving unsigned and signed - The signed data will be converted to unsigned - Refer arithemetic conversion rules in K&R
24. #error is used for displaying an error while compilation. for eg.
#ifdef ABC printf(”ABC”); #else #ifdef DEF printf(DEF); #else #error “Declaration not done” #endif
30. Hard RTOS is system which will be having major problems if the specified time limit is crossed. For eg. missiles Soft RTOS is systems which will not be having major problems if the specified limit is crossed. For eg. real time audio steaming. But for both exceeding the time limit is concidered as error.
31. Interrupt latency is the time period between interrupt on the pin to the execution of 1st instuction in the interrupt routine. THis will depend upon the processor. If the execution time for the instruction is less (like in RISC) this time will also be less. If register storage is required the time will be less in the processors in which remapping of registers is present as this can be done in a single instruction.
32. RTOS systems are embedded systems with time criticality. 33.
Tech Interviews comment by deepak
15.
What is interrupt latency? It is the time interval between an interrupt has occured till the time it has been serviced. Mathematically:
Int(lat)= rt+pt+dt
where rt=recognition time pt=process time dt=dispatch time
Tech Interviews comment by Ramesh K.B.
16.
Q. Write a function to reverse contents in a single linked list without reversing the links? Can anyone pls help me out?
Tech Interviews comment by Ramesh K.B.
17.
Q.Can we have a constant volatile variable?
Soln: YES.We can have a const volatile variable. Volatile variable is one which can be changed by user,ie programmer as well as by the external events.If we declare it as const volatile,then user cannot change but can be changed by the hardware.
Tech Interviews comment by Ramesh K.B.
18.
20. malloc(sizeof(0)) will return — valid pointer yes. sizeof(0) –> int size and it is 4
25. itoa(…) itoa(pointer to storage buffer,int to convert, base(eg.binary,oct,hex,dec))
33. typedef struct regset{ unsigned char onebit:1; unsigned char twobit:2; …. }regset;
Tech Interviews comment by Ramesh.V
19.
i have an query regarding , interupts in Embedded systems
can we use the interrupt function call same as ordinary function,i.e. can we pass arguments and return values from an ISR routine.
Tech Interviews comment by Sushil Rana
20.
what happens when we put an infinite loop using for
for(;;) what is the condition expression value by default.
Tech Interviews comment by Sushil Rana
21.
Write a function to reverse contents in a single linked list without reversing the links? Can anyone pls help me out?
Count number of nodes in the linear linked list. Let say cnt is the number of nodes and index = 0. You can swap content of index th node and cnt-index th node, each time increment index by 1. All the contents will be reversed.
Tech Interviews comment by Hetal
22.
Scope of static variables? scope of static variables is limited to the local function in which it is defined and to the functions calling the stattic variable.
Tech Interviews comment by Guneet
23.
How virtual tables are created in case of abstract classes? Is it the same as in non-abstract classes? Virtual tables r created on stack or Heap?
Tech Interviews comment by Satish Parande
24.
why only reference is passed as a parameter in Copy constructor? why not address?
Tech Interviews comment by Satish Parande
25.
is it possible to call delete from the class member function ?
Tech Interviews comment by Mrinmay Biswas
26.
q.3. —- Inline is only a request that may be rejected also based on optimization policies,while macro is immediately replaced before compilation. —- type checking is not possible in Macros, but in inline its possible.
1. Can structures be passed to the functions by value? 1.結構体是否能传值给函数?
2. Why cannot arrays be passed by values to functions? 2.为什么数组不能传值给函数?
3. Advantages and disadvantages of using macro and inline functions? 3.宏定义和内联函数的利弊是什么?
4. What happens when recursion functions are declared inline? 4.将递归函数定义为内联函数会出现什么情况?
5. Scope of static variables? 5.静态变量的有效范?
6. Difference between object oriented and object based languages? 6.面向对象与面向基础的区别是什么?
7. Multiple inheritance - objects contain how many multiply inherited ancestor? 7.多态继承能包含多少祖先级的多态?
8. What are the 4 different types of inheritance relationship? 8.4种继承关系是什么?
9. How would you find out the no of instance of a class? 9.如何找出无实例类?
10. Is java a pure object oriented language? Why? 10.JAVA是纯面向对象语言吗?为什么?
11. Order of constructor and destructor call in case of multiple inheritance? 11.是否允许再多态种调用构造函数和析构函数?
12. Can u have inline virtual functions in a class? 12.在你的类种是否会含有内联虚函数?
13. When you inherit a class using private keyword which members of base class are visible to the derived class? 13.在什么情况下你继承的私有类种成员是基类的显性成员?
14. What is the output of printf("\nab\bcd\ref"); -> ef 14.printf("\nab\bcd\ref"); 会输出什么?
15. #define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives preprocessor warning. Why? 15.#define cat(x,y) x##y 链接 x to y.但是cat(cat(1,2),3)不能扩展同时会有预处理警告,为什么?
16. Can you have constant volatile variable? Yes, you can have a volatile pointer? 16.是否可以有可变恒常量?如果是是否有可变指针?
17. ++*ip increments what? it increments what ip points to 17++*ip增加了什么?它将IP指向了什么?
18. Operations involving unsigned and signed — unsigned will be converted to signed 18.操作类型包括符号型和非符号型---非符号型会转换成符号型?
19. a+++b -> (a++)+b 19.a+++b->(a++)+b ji
20. malloc(sizeof(0)) will return — valid pointer 20.malloc(sizeof(0)) 将会返回的有效指针
21. main() {fork();fork();fork();printf("hello world"); } — will print 8 times. 21.main() {fork();fork();fork();printf("hello world"); } 会打印8次?
22. Array of pts to functions — void (*fptr[10])() 22.指针数组函数 void (*fptr[10])()
23. Which way of writing infinite loops is more efficient than others? there are 3ways. 23.如何写死循环更有效?
24. # error — what it does? 24.#ERROR是干吗的?
25. How is function itoa() written? 25.如何实现itoa()?
26. Who to know wether system uses big endian or little endian format and how to convert among them? 26.谁去分析系统使用了大系统还是小系统。(大头小头)
Intel的AISC指令都是低字节在前,苹果等Power PC的cpu使用的是RISC指令集,都是高字节在前。如何转变他们?
27. What is interrupt latency? 27.什么是中断响应?
28. What is forward reference w.r.t. pointers in c? 28.什么在C中分析w.r.t. pointers?
29. How is generic list manipulation function written which accepts elements of any kind?
30. What is the difference between hard real-time and soft real-time OS? 30.软实时操作系统和硬实时操作系统的区别?
31. What is interrupt latency? How can you recuce it? 31.什么是中断潜伏?你如何识别它?
32. What is the differnce between embedded systems and the system in which rtos is running? 32.嵌入式操作系统和实时操作系统的区别?
33. How can you define a structure with bit field members? 33.如何定义 bit field members的結構体
34. What are the features different in pSOS and vxWorks? 34.PSOS和VXWORKS功能区别有那些?
35. How do you write a function which takes 2 arguments - a byte and a field in the byte and returns the value of the field in that byte? 35......
36. What are the different storage classes in C? 36.C中的存储类有什么不同?
37. What are the different qualifiers in C? 37.C中有什么不同的限定?
38. What are the different BSD and SVR4 communication mechanisms BSD与SVR4通讯有什么不同?
Persional Prospectives:
1.
Q1. No they are always passed by reference. Think. Size of structure can be arbitrarily large. Q2. Same as above. Q5. Lifetime of process. Q9. Declare a static variable, class variable, and increment(decrement) for every constructor (destructor) called. Q11. Constructor. Base to current. Destructor. current to base. Both are done recursuively. Q13. NONE Q14. $> acd ef ->ef is wrong, what happened to acd? Q16. You can have a constant pointer to a volatile variable but not a constant volatile variable. Q26. Write a union of int and 2 chars. Store as int retrieve as chars. Q 27. Time taken between INT req and INT service. Q33. Study Let us C, Yeshwant Kanetkar
Tech Interviews comment by Taran
2.
Q. 13 Answer posted is wrong. Public & protected members of base class will be visible to derived class, but not its objects.
Tech Interviews comment by Sumeet
3.
Q1 - YES, a complete structure can be passed. Regarding the size, it is true that they can be very large and hence it is not a good practice to do so. In any case, one can do if one wants to.
Tech Interviews comment by Bhaskar
4.
Q3. When using macro you can’t use data type while passing it. But in Inline function you can have data types so that it can be checked. e.g MACRO : ADD(a,b) INLINE : inline void Add(int a,int b );
Tech Interviews comment by VijayaKumar
5.
Q1. Yes structure can be passed by value but the overhead of copying large values will be there. hence not usable. We should pass it by pointer. Q2. Individual element can be passed by value of course. But not whole array. Q5. It is alive lifetime of process, and its scope is limited to function in which it is defined. file1.c ********** static int i; void main() { …….. } file2.c ********** extern int i; //error
If declared global then it is visible in that file only. Q6. Object oriented language have Inheritance, polymorphism etc. But object based language only deal with object. Q7. If class D:public A,B,C {} then three ancestors Q8. public ,private, protected, virtual Q30. Hard RTS is having deadline defined and it is life critical ,should be reliable. late answer is wrong answer. in Soft RTS,process time should be predictable and reliable.
Tech Interviews comment by Pawan Kumar
6.
Q36.What are the different storage classes in C? A:Auto,Register,Static,Extern
Tech Interviews comment by MKS
7.
Q5 Scope of static variables is only within the block where it is declared. But the lifetime is till the process is running
Tech Interviews comment by Satish Parande
8.
Questin???
How can we dynamically allocate memory without using malloc() or calloc() or realloc()?Explain in Breif.
Can any one help in finding this answer to this question……
Tech Interviews comment by Midhun V
9.
In Java, we place even the Main() function inside a CLASS. But it is not the case with C++.
So, i think this is one of the answers you can say, JAVA is Fully Obejct Oriented.
Tech Interviews comment by vsvraju
10.
Q11 : Base-class constructors are called in the order in which inheritance is specified in the derived-class definition. The order in which the Base-class constructors are specified in the derived-class member initializer list does not effect the order of construction.
Tech Interviews comment by vsvraju
11.
Q 12: Yes we can have. you are never guaranteed that a routine is inlined. It is only a suggestion to the compiler. If the routine is either too complicated or a virtual function,then a static copy of the routine will be placed in the compiled module. Thus, a routine that was coded as inline may cause a performance degradation because it may consume much more space when it is not physically inlined. With a virtual function, a copy of that routine will be created for every module that has at least one instantiation of that class.
Q 13: NONE. None of the Public, Protected and Private data members are visible.
Q 16: YES. We can have a const volatile variable. a volatile variable is a variable which can be changed by the extrenal events (like an interrput timers will increment the voltile varible. If you dont want you volatile varibale to be changed then declare them as “const volatile”.
Q 17. I will explain this with an example:
int a = 10; int *p = &a; // suppose &a = 4010 (address of a)
Because both ++ and * are unary operators, the are calculated from right to left –> ++ (*p)
++*p will inrement 4010 by 4 (int size) -> ++*p will have the value 4014.
Q 21: It will print 8 times. Because, each fork will print twice. if u flush, (using “fflush”), then it will be printed only once. thats is you need to flush the iostreams.
Q 30:
In Hard RTOS the latency should be less the 20ns (nano sec) in Soft RTOS the latency range 3ns - 20ns is also acceptable.
Tech Interviews comment by vsvraju
12.
I THINK A BALOON CAN HAVE TO MUCH ELECTRICITY
Tech Interviews comment by SANDRA
13.
Java is not a pure object oriented language as “everything” in java is not an object. It still has primitive data types such as int, char, etc. which are NOT objects. Ruby is an example of a pure object oriented language, where “everything” is an object, even int.
Tech Interviews comment by Karan
14.
16. It is possible to have “const volatile” declaration. This indicates that the variable defined like this is not possible to change within that context. It can be changed by an external event. const declaraion just says that it will be readonly within the context, that area can be modified by an interrupt routine or another process.
18. Operations involving unsigned and signed - The signed data will be converted to unsigned - Refer arithemetic conversion rules in K&R
24. #error is used for displaying an error while compilation. for eg.
#ifdef ABC printf(”ABC”); #else #ifdef DEF printf(DEF); #else #error “Declaration not done” #endif
30. Hard RTOS is system which will be having major problems if the specified time limit is crossed. For eg. missiles Soft RTOS is systems which will not be having major problems if the specified limit is crossed. For eg. real time audio steaming. But for both exceeding the time limit is concidered as error.
31. Interrupt latency is the time period between interrupt on the pin to the execution of 1st instuction in the interrupt routine. THis will depend upon the processor. If the execution time for the instruction is less (like in RISC) this time will also be less. If register storage is required the time will be less in the processors in which remapping of registers is present as this can be done in a single instruction.
32. RTOS systems are embedded systems with time criticality. 33.
Tech Interviews comment by deepak
15.
What is interrupt latency? It is the time interval between an interrupt has occured till the time it has been serviced. Mathematically:
Int(lat)= rt+pt+dt
where rt=recognition time pt=process time dt=dispatch time
Tech Interviews comment by Ramesh K.B.
16.
Q. Write a function to reverse contents in a single linked list without reversing the links? Can anyone pls help me out?
Tech Interviews comment by Ramesh K.B.
17.
Q.Can we have a constant volatile variable?
Soln: YES.We can have a const volatile variable. Volatile variable is one which can be changed by user,ie programmer as well as by the external events.If we declare it as const volatile,then user cannot change but can be changed by the hardware.
Tech Interviews comment by Ramesh K.B.
18.
20. malloc(sizeof(0)) will return — valid pointer yes. sizeof(0) –> int size and it is 4
25. itoa(…) itoa(pointer to storage buffer,int to convert, base(eg.binary,oct,hex,dec))
33. typedef struct regset{ unsigned char onebit:1; unsigned char twobit:2; …. }regset;
Tech Interviews comment by Ramesh.V
19.
i have an query regarding , interupts in Embedded systems
can we use the interrupt function call same as ordinary function,i.e. can we pass arguments and return values from an ISR routine.
Tech Interviews comment by Sushil Rana
20.
what happens when we put an infinite loop using for
for(;;) what is the condition expression value by default.
Tech Interviews comment by Sushil Rana
21.
Write a function to reverse contents in a single linked list without reversing the links? Can anyone pls help me out?
Count number of nodes in the linear linked list. Let say cnt is the number of nodes and index = 0. You can swap content of index th node and cnt-index th node, each time increment index by 1. All the contents will be reversed.
Tech Interviews comment by Hetal
22.
Scope of static variables? scope of static variables is limited to the local function in which it is defined and to the functions calling the stattic variable.
Tech Interviews comment by Guneet
23.
How virtual tables are created in case of abstract classes? Is it the same as in non-abstract classes? Virtual tables r created on stack or Heap?
Tech Interviews comment by Satish Parande
24.
why only reference is passed as a parameter in Copy constructor? why not address?
Tech Interviews comment by Satish Parande
25.
is it possible to call delete from the class member function ?
Tech Interviews comment by Mrinmay Biswas
26.
q.3. —- Inline is only a request that may be rejected also based on optimization policies,while macro is immediately replaced before compilation. —- type checking is not possible in Macros, but in inline its possible.
訂閱:
文章 (Atom)