Embedded systems interview questions

来源:互联网 发布:diy willem编程器 编辑:程序博客网 时间:2024/05/16 10:23
  1. Can structures be passed to the functions by value?
  2. Why cannot arrays be passed by values to functions?
  3. Advantages and disadvantages of using macro and inline functions?
  4. What happens when recursion functions are declared inline?
  5. Scope of static variables?
  6. Difference between object oriented and object based languages?
  7. Multiple inheritance - objects contain howmany multiply inherited ancestor?
  8. What are the 4 different types of inheritance relationship?
  9. How would you find out the no of instance of a class?
  10. Is java a pure object oriented language? Why?
  11. Order of constructor and destructor call in case of multiple inheritance?
  12. Can u have inline virtual functions in a class?
  13. When you inherit a class using private keyword which members of base class are visible to the derived class?
  14. What is the output of printf("/nab/bcd/ref"); -> ef
  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?
  16. Can you have constant volatile variable? Yes, you can have a volatile pointer?
  17. ++*ip increments what? it increments what ip points to
  18. Operations involving unsigned and signed — unsigned will be converted to signed
  19. a+++b -> (a++)+b
  20. malloc(sizeof(0)) will return — valid pointer
  21. main() {fork();fork();fork();printf("hello world"); } — will print 8 times.
  22. Array of pts to functions — void (*fptr[10])()
  23. Which way of writing infinite loops is more efficient than others? there are 3ways.
  24. # error — what it does?
  25. How is function itoa() written?
  26. Who to know wether systemuses big endian or little endian format and how to convert among them?
  27. What is interrupt latency?
  28. What is forward reference w.r.t. pointers in c?
  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?
  31. What is interrupt latency? How can you recuce it?
  32. What is the differnce between embedded systems and the system in which rtos is running?
  33. How can you define a structure with bit field members?
  34. What are the features different in pSOS and 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?
  36. What are the different storage classes in C?
  37. What are the different qualifiers in C?
  38. What are the different BSD and SVR4 communication mechanisms
  1. Taran said,

    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

  2. Sumeet said,

    Q. 13
    Answer posted is wrong.
    Public & protected members of base class will be visible to derived class, but not its objects.

  3. Bhaskar said,

    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.

  4. VijayaKumar said,

    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 );

  5. Pawan Kumar said,

    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.

  6. MKS said,

    Q36.What are the different storage classes in C?
    A:Auto,Register,Static,Extern

  7. Satish Parande said,

    Q5 Scope of static variables is only within the block where it is declared.
    But the lifetime is till the process is running

  8. Midhun V said,

    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……

  9. vsvraju said,

    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.

  10. vsvraju said,

    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.

  11. vsvraju said,

    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.

  12. SANDRA said,

    I THINK A BALOON CAN HAVE TO MUCH ELECTRICITY

  13. Karan said,

    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.

  14. deepak said,

    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.

  15. Ramesh K.B. said,

    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

  16. Ramesh K.B. said,

    Q. Write a function to reverse contents in a single linked list without reversing the links?
    Can anyone pls help me out?

  17. Ramesh K.B. said,

    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.

  18. Ramesh.V said,

    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;

  19. Sushil Rana said,

    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.

  20. Sushil Rana said,

    what happens when
    we put an infinite loop using for

    for(;;)
    what is the condition expression value by default.

  21. Hetal said,

    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.

  22. Guneet said,

    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.

  23. Satish Parande said,

    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?

  24. Satish Parande said,

    why only reference is passed as a parameter in Copy constructor? why not address?

  25. Mrinmay Biswas said,

    is it possible to call delete from the class member function ?

  26. Praveen said,

    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.

  27. kaushik chakraborty said,

    30 . With all the new things going on in embedded device software and support, we thought now would be a good time to pour the RTOS chaos out on a big table, sort out the pieces, and see how the whole thing fits together (or doesn’t) for the average system designer. After all, confusion abounds in the RTOS realm. With hard- and soft-RTOS, device software, embedded OS, open-source, commercial, commercial open-source, commercial-grade open-source, royalty-free… there is a confluence of ambiguous labels and categorizations constantly conspiring to confuse us as we seek to select the best OS for our embedded system.

    Wind River’s announcements may help to tame some modicum of the mayhem. With the company’s recently revised direction now coming into solid focus, the leading RTOS vendor is telling us that they’ll be doing two major announcements and releases per year now, one in the fall, and one in the spring. They further break down their RTOS offering into two major categories – Commercial Linux and Commercial RTOS.

    A few weeks ago, in “The People’s RTOS”, we took an in-depth look at Wind River’s Linux offering, but that’s only half of the story. In their most recent announcement, Wind River points out that they also lay claim to a full 42% of the 50% of the RTOS market that makes up commercial RTOS, while their commercial embedded Linux offering has skyrocketed to a full 39% of the 26% of the market that’s using commercial Linux. Competitor Green Hills is happy to help our understanding with the further observation that their market share is growing faster than any other vendor, and analysts chime in that the entire market is now growing at an annual rate of 16-20%. Confused yet? Just whip out a PO and buy one already. The pain won’t stop until you do.

    However, if we want to delve deeper than market share estimates in making one of our most critical embedded system design decisions, perhaps we should look at the RTOS question from a more technical point of view. Let’s pocket that PO for awhile and do a bit more research. RTOS is one of the most over-applied and misused terms floating through the embedded technology space, and it pays to pause and take technical stock of what we’re all talking about.

    “RTOS” stands for Real Time Operating System, of course, but current common usage has expanded to include pretty much any operating system that isn’t running on a traditional, general-purpose computer. Some have migrated to the more general “embedded” operating system terminology, but even the “embedded” concept has fallen out of favor in some circles, in favor of “device” software or OS. Speaking of circles (and maybe in circles), just about every OS runs on a “device” (hey, a supercomputer is a device, right?) so we’ll probably just continue to abuse the “RTOS” term until someone comes up with something clearly better.

    You can slice and dice the RTOS world several ways, and it’s important to understand a few of these. First is the concept of “hard” versus “soft” RTOS. Hard RTOS is where the “Real Time” components are in all capitals. If your application requires a predictable latency (always, really, no kidding, no matter what), and the consequences of missing an event deadline are catastrophic, you’re probably in the market for a hard RTOS. If you don’t mind if the RTOS you’re using takes an occasional brief vacation to manage memory or do some other housekeeping task (as long as it’s pretty snappy in interrupts most of the time), you’re probably more on the soft RTOS side of things.

    Hard RTOS, such as VxWorks (from Wind River), QNX, pSOS, eCos, OSE and LynxOS (which offer a hard RTOS overlay/extension for real-time operation of Linux applications), INTEGRITY (From Green Hills Software), ThreadX (From both Express Logic and Green Hills Software), Microware OS-9 (from RadiSys), Windows CE, and Nucleus (from Mentor Graphics’s/Accelerated Technology), go to great lengths to provide 100% predictable response to interrupts.

    Soft RTOS, such as embedded versions of Windows (except CE), Linux, and other modified or ported versions of general-purpose operating systems may have excellent response to interrupts, but do not guarantee that there will never be a longer than expected interrupt latency. It is important to remember the difference between performance and predictability in this case. A hard RTOS may not always have the best performance in terms of interrupt latency, but it will have predictable response so you can reliably plan your system design around it. A soft RTOS, even though it may sometimes have a shorter average interrupt latency, does not absolutely guarantee the timing.

    In addition to interrupt latency, it is also important to consider context switch time in evaluating RTOS performance. Context switch time is the amount of time your RTOS takes to save state for one task, load the context for another task, and begin execution. Measurement techniques for context switch time vary significantly, however, as there is no clear standard on what to measure, and also a large variation in performance depending on what amount of state information must be saved.

    It also pays to understand the difference between a static and a dynamic RTOS. In a dynamic RTOS, the system can change on-the-fly without stopping and reloading. A dynamic RTOS has a dynamic scheduler that can re-compute task priorities while running depending on the criticality of the task.

    Scheduling algorithms used in RTOS vary widely, and a detailed discussion is beyond the scope of this article. However, the selection of the most appropriate scheduling approach depends on the particular requirements of your application. For example, do some tasks have more flexibility in latency than others? Are some tasks regular while others happen very infrequently or irregularly? Are the consequences for missing a deadline dramatically different for different tasks that are being scheduled? All of these considerations come into play in picking the best scheduling scheme, which may affect your choice of RTOS.

    Next, we need to look at memory footprint, because embedded OS and RTOS sizes can vary dramatically. Some systems are designed for use in very low-cost, space-constrained portable devices with miserly memory allocations. Others are designed for very large and complex systems, rivaling (and sometimes exceeding) even the complexity of many general-purpose computers. A few are scalable depending on the complexity of your application and the size of the footprint you can tolerate. You can decide which OS components you need and custom-configure an OS that meets your needs (or is the best compromise) in space, speed, and capability.

    One final consideration is the choice of an open-source, commercial-grade open-source, or commercial OS. Open source RTOS (like embedded Linux) exploded in popularity a few years ago due to the lack of licensing and royalty fees, the unlimited customizability, and the easy access to expert developers. Unfortunately, many design teams discovered the ugly side of this tradeoff as well – proliferation of many disparate versions, unlimited customizability, and complete lack of support. These deficiencies led to the creation of “commercial” and “commercial grade” open source RTOS.

    Wind River tells us that these commercialized versions of Linux are rapidly gaining acceptance and market share, primarily at the expense of in-house development (based mostly on non-commercial open-source RTOS). Many teams see the best of both worlds in the commercially supported and tested open-source segment.

    Interestingly, the commercial RTOS market has largely held its own lately against the open-source incursion. For many companies, the additional level and single point of accountability has high value. For companies involved in high-security or defense-related design, there may be additional requirements (such as mandatory domestic content) that cannot be served by any open-source system. Commercial RTOS are also available on royalty-based and royalty-free variants, and the licensing business model may affect our engineering decision as well.

    Speaking of security, all forms of protection are increasing in importance these days. Consumer electronics companies want to protect their valuable IP from unscrupulous copycats. Companies developing networked applications want solid security strategies to reassure customers that their data is safe in the hands of their embedded devices, and military and government applications still see system security as highest priority. Wind River’s recent announcement, for example, prominently mentions a number of security-related enhancements. Security can’t be an afterthought in a new system design, so we should always make a careful assessment of our system’s particular security requirements before we start locking ourselves into a particular system architecture.

    So what RTOS will your embedded design be wearing this fall? With the fantastic array of available options, the hardest part is sometimes just choosing one. If nothing grabs your attention, though, don’t despair. Spring is just around the corner and we’re sure to see a whole new lineup of device software wonderment just in time for the change of season.

  28. kaushik chakraborty said,

    30.
    Hard and Soft Real-Time Systems
    A classification can be made into hard and soft real-time systems based on their properties.
    The properties of a hard real-time system are:

    No lateness is accepted under any circumstances
    Useless results if late
    Catastrophic failure if deadline missed
    Cost of missing deadline is infinitely high
    A good example of a hard real-time system is the fly-by wire control system of an aircraft.
    A soft real-time system is characterised by:

    Rising cost for lateness of results
    Acceptance of lower performance for lateness
    Examples are a vending machine and a network interface subsystem. In the latter you can recover from a missed packet by using one or another network protocol asking to resend the missed packet. Of course, by doing so, you accept system performance degradation.
    Other real-time systems examples are nuclear power plant control, industrial manufacturing control, me-dical monitoring, weapon delivery systems, space na-vigation and guidance, reconnaissance systems, laboratory experiments control, automobile engines control, robotics, telemetry control systems, printer controllers, anti-lock breaking, burglar alarms — the list is endless.
    The difference between a hard and a soft real-time system depends on the system requirements: it is called hard if the requirement is “the system shall not miss a deadline” and soft if “the system should not miss a deadline”.
    There are a lot of discussions going on about the exact meaning of a hard and soft real-time system. One could even argue that a soft real-time system is not a real-time system, as the first requirement: meet deadlines, is not met. Indeed, the term “real-time” is often misused to indicate a fast system. And fast can then be seen as “should meet timing deadlines”, thus meaning a soft real-time system. Therefore, we define a RTOS as an OS that can be used to build a hard real-time system.

    Hard or Soft RTOS do not exist!
    People often confuse the notion of real-time systems with real-time operating systems (RTOS). From time to time people, even misuse hard and soft attributes. They say this RTOS is a hard RTOS or this one is a soft one. There is no hard RTOS or soft RTOS. A specific RTOS can only allow you to develop a hard real-time system. But having such an RTOS will not prevent you from developing a system that does not meet deadlines.
    If, for example, you decide to build a real-time system that should respond to an Ethernet TCP/IP connection, it will never be a hard real-time system as the Ethernet itself is never predictable.
    Of course, if you decide to build an application on top of an OS like “Windows 3.11”, your system will never be a hard real-time system as the behaviour of the “OS” software is by no means predictable.

  29. kaushik chakraborty said,

    Difference between Semaphore & Mutex
    ====================================
    by default mutex is full(1) but by default semaphore is empty(0). semaphore can be 2 types.
    1) binary semaphore
    2) counting semaphore
    The binary semaphore can have the value of 1 or 0 but counting semaphore can have any numaric values.

    mutex is similar to binary semaphore, but the difference between both of them is as exaplain above and the following one.

    If a resource is locked by a thread using mutex, then that particular thread only can unlock that resource, but in the case of semaphore, if any resource is locked by semaphore then that lock can be released or the resource can be unlocked by any thread according to the algorithm used for developing the code for that.

  30. Anand said,

    /* Function to reverse singly link list */
    void reverse(NODE *head)
    {
    NODE *prev, *nxt, *current;

    prev = NULL;
    current = head;

    while(current != NULL) {
    nxt = current->next;
    current->next = prev;
    prev = current;
    current = nxt;
    }
    return(prev);
    }

  31. Anand said,

    void reverse(NODE *head)

    should be

    NODE *reverse(NODE *head)

  32. Anand said,

    void fun_atoi()
    {
    char *p=”128″;
    int n=0;

    while(*p != ”)
    n = n * 10 + *p++ - ‘0′;

    printf(”/n %d/n”, n);
    }

  33. Anand said,

    write a program to find whether no is power of two or not?

    ANS: when no is power of two then only one bit will be set to 1.

    Normally we check all the bits and if count = 1 then
    we say no is power of two. Now its worst and best case time comlexity will be O(n) = n where n is the total no of bits.

    even we can write same program with constant time complexity O(n) = 1 as follows

    if ((n &(n-1)) == 0)
    printf(”Power of two!”);

    it takes constant time complexity.

  34. Anand said,

    Ramesh K.B. said,

    Q. Write a function to reverse contents in a single linked list without reversing the links?
    Can anyone pls help me out?

    ANS:

    void print_reverse(NODE *head)
    {
    NODE *stored, *list;

    stored = NULL;

    while (head != stored) {
    for(list = head; list->next != stored; list=list->next);
    stored = list;
    printf(”%d”, list->data);
    }

    }

  35. srinivas said,

    HI to everybody

    can any body tell me wht make the scheduler to invoke the blocked task when the other task releases semaphore

    is it done by a interrupt or some thing else

    this was the question asked by interviewer to me and i said its interrupt i think i am correct, if not just mail me

    thanks in advance for ur asnwer

    thanku

  36. srinivas said,

    Q.

    how to find the header(first node) if the pointer to tail(last node )is given in a single linked list?

    anyone please help me

  37. divya said,

    hi, plzzzzzzzzz help me in this following Qestions

    1)What is Memory MEMLOC ? How do express, where do use it?
    2)What is data structure? How do you write data structure in “C” cod ?
    3)What is the Function call, where do you?
    4) How do you express binary to hex or hex to binay conversion in”C” code?
    5) Write sort algoritham dn prepare “C” code

  38. Sathiyanarayanan said,

    Q15:
    Macro expanding becomes illegal if done recursively

  39. vaishali said,

    What is the output of printf(”/nab/bcd/ref”); -> ef
    wrong!!

    the answer comes out to be efd

  40. Neeraj said,

    Q1. Can structures be passed to the functions by value?
    A1. Yes, by default they are passed by value

    Q2. Why cannot arrays be passed by values to functions?
    A2 array name is itself a pointer to zero element in array

    Q4. Scope of static variables?
    A4. If defined inside function, scope is limited in the function. If defined inside the file outside the function than they r global variable but scope limited to the file in which its defined

    Q11. What is the output of printf(”/nab/bcd/ref”);
    A. efd

    Q12. #define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives preprocessor warning. Why?
    A. lvalue required

    Q13. Can you have constant volatile variable? Yes, you can have a volatile pointer?
    A. Yes in both case

    Q14. ++*ip increments what?
    A. increment what ip points to

    Q15. Operations involving unsigned and signed
    A. signed will be prmoted to unsigned

    Q16. a+++b
    A. a++ + b

    Q17. malloc(sizeof(0)) will return
    A. Valid pointer

    Q18.main() {fork();fork();fork();printf(”hello world”); }
    A. will print 8 times.

    Q19. Array of pts to functions
    A. void (*fptr[10])()

    Q20.Which way of writing infinite loops is more efficient than others?
    A. there are 3ways.
    while(1)
    {;}

    for(;;)
    {;}

    label:
    goto label;

    Q21. # error ? what it does?
    A. preprocessor will generate error message and causes the compilation to fail

    Q23. Who to know wether systemuses big endian or little endian format and how to convert among them?
    A. main()
    {
    int a=0×1;
    if(*(char *)&a == 1)
    printf(”little endian”);
    else
    printf(”big endian”);
    }

    Q30. How can you define a structure with bit field members?
    A. struct abc {
    unsigned int a:1;
    unisgned int b:2;
    };

    Q33. What are the different storage classes in C?
    A. automatic & static

    Q34. What are the different qualifiers in C?
    A. const & volatile

  41. Neeraj said,

    Q32. 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?
    A.int func(char a, int n)
    {return a & (1

 
原创粉丝点击