Professional Documents
Culture Documents
Structures:
1. What is the difference between Structure and Union?
Structure allocates the memory as per the Data type
Union is Allocate the Memory in max size of Declare the variables to all.
5. What are bit fields? What is the use of bit fields in a structure declaration?
A bit field is an element of a struct or union, having an integer type but a specified "width," or number of
bits. You can have, for example, a three-bit signed integer or a five-bit unsigned integer, and so on. There
are restrictions on what "underlying types" can be used, and on what widths are possible. Also, it is not
possible to form a pointer to a bit field (hence,it is not possible to create an array of bit fields).
struct packed_struct
{
unsigned int f1:1;
unsigned int type:4;
unsigned int funny_int:9;
} pack;
Pointers:
8. When would you use a pointer to a function?
Pointers to functions are interesting when you pass them to other functions. A function that takes function
pointers says, in effect, Part of what I do can be customized. Give me a pointer to a function, and I will
call it when that part of the job needs to be done. That function can do its part for me. This is known as a
callback. It’s used a lot in graphical user interface libraries, in which the style of a display is built into the
library but the contents of the display are part of the application.
As a simpler example, say you have an array of character pointers (char*s), and you want to sort it by the
value of the strings the character pointers point to. The standard qsort() function uses function pointers to
perform that task. qsort() takes four arguments,
11. How I can add two numbers in c language without using Arithmetic operators?
By using bitwise operators it is possible, for example a=8,ie in binary(00001000) & b=4 in binary
(00000100)if we add a,b then we get 12 in binary(00001100)..if u add the binary a,b & convert the answer
in to decimal we get 12.. in the c code is:
void main()
{
int a=8,b=4,c;
clrscr();
c=a^b;
printf("%d",c);
getch();
}
So, by using ^ operator we can do that in c.
int i = 0;
int *ip01 = & i;
int **ip02 = & ip01;
int ***ip03 = & ip02;
int ****ip04 = & ip03;
int *****ip05 = & ip04;
int ******ip06 = & ip05;
int *******ip07 = & ip06;
int ********ip08 = & ip07;
int *********ip09 = & ip08;
int **********ip10 = & ip09;
int ***********ip11 = & ip10;
int ************ip12 = & ip11;
************ip12 = 1; /* i = 1 */
The ANSI C standard says all compilers must handle at least 12 levels. Your compiler might support
more.
int *ip;
ip points to an int. If you write
void *p;
p doesn’t point to a void!
In C and C++, any time you need a void pointer, you can use another pointer type. For example, if you
have a char*, you can pass it to a function that expects a void*. You don?t even need to cast it. In C (but
not in C++), you can use a void* any time you need any kind of pointer, without casting. (In C++, you
need to cast it).
A void pointer is used for working with raw memory or for passing a pointer to an unspecified type.
Some C code operates on raw memory. When C was first invented, character pointers (char *) were used
for that. Then people started getting confused about when a character pointer was a string, when it was a
character array, and when it was raw memory.
3
A pointer value is a data object that refers to a memory location. Each memory location is numbered in
the memory. The number attached to a memory location is called the address of the location.
Arrays:
26. Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
It’s easier for a C compiler to generate good code for pointers than for subscripts.
Array subscripts are ultimately resolved into pointer form. Like a[i] -> *(a+i). So the pointer form is always
better.
main()
{
int size;
printf("Enter array size");
scanf("%d",&size);
int array[size];
/* Remaining code*/
}
Theoretically, this is true but this type of code is not implemented in real-time application. This type of
code is poor programming practice but still the code works.
Functions:
28. What are the advantages of the functions?
Debugging is easier<br><br>?It is easier to understand the logic involved in the program<br><br>?
Testing is easier<br><br>?Recursive call is possible<br><br>?Irrelevant details in the user point of view
are hidden in functions<br><br>?Functions are helpful in generalizing the program
1. Code Re usability 2. Occupies less memory 3. Resilience 2 change i.e. error handling is easy 4. Logic
becomes clear 5. Compiler takes less time 2 compile the program
Thus, the choice between using a macro and using a function is one of deciding between the tradeoff of
faster program speed versus smaller program size. Generally, you should use macros to replace small,
repeatable code sections, and you should use functions for larger coding tasks that might require several
lines of code.
Basics:
33. Can you define which header file to include at compile time?
Yes. This can be done by using the #if, #else, and #endif pre-processor directives. For example, certain
compilers use different names for header files. One such case is between Borland C++, which uses the
header file alloc.h, and Microsoft C++, which uses the header file malloc.h. Both of these headers serve
the same purpose, and each contains roughly the same definitions. If, however, you are writing a
program that is to support Borland C++ and Microsoft C++, you must define which header to include at
compile time. The following example shows how this can be done:
#ifdef _ _BORLANDC_ _
#include <alloc.h>
#else
#include <malloc.h>
#endif
Conversely, you can turn off loop optimization by inserting the following line into your code:
#pragma loop_opt(off)
39. What is the difference between #include <file> and #include “file”
The difference is when u mentions the filename in double quotes the compiler will search for the file in
current working directory or the directory in which the source file is present. If the header file is not found
there it then searches in the C standard Library(location where stdio.h etc are found).
<file> will cause the compiler to search in C standard Library.
5
41. Can a variable be both constant and volatile?
Yes. The const modifier means that this code cannot change the value of the variable, but that does not
mean that the value cannot be changed by means outside this code. For instance, in the example in FAQ
8, the timer structure was accessed through a volatile const pointer.
The function itself did not change the value of the timer, so it was declared const. However, the value
was changed by hardware on the computer, so it was declared volatile. If a variable is both const and
volatile, the two modifiers can appear in either order.
51. Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object'
file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces
the machine language instructions that correspond to the source code file that was compiled. For
instance, if you compile (but don't link) three separate files, you will have three object files created as
output, each with the name <filename>.o or <filename>.obj (the extension will depend on your compiler).
Each of these files contains a translation of your source code file into a machine language file -- but you
can't run them yet! You need to turn them into executables your operating system can use. That's where
the linker comes in.
52. Linking refers to the creation of a single executable file from multiple object files. In this step, it is
common that the linker will complain about undefined functions (commonly, main itself). During
compilation, if the compiler could not find the definition for a particular function, it would just assume that
the function was defined in another file. If this isn't the case, there's no way the compiler would know -- it
doesn't look at the contents of more than one file at a time. The linker, on the other hand, may look at
multiple files and try to find references for the functions that weren't mentioned.
You might ask why there are separate compilation and linking steps. First, it's probably easier to
implement things that way. The compiler does its thing, and the linker does its thing -- by keeping the
functions separate, the complexity of the program is reduced. Another (more obvious) advantage is that
this allows the creation of large programs without having to redo the compilation step every time a file is
changed. Instead, using so called "conditional compilation", it is necessary to compile only those source
files that have changed; for the rest, the object files are sufficient input for the linker. Finally, this makes it
simple to implement libraries of pre-compiled code: just create object files and link them just like any
other object file. (The fact that each file is compiled separately from information contained in other files,
incidentally, is called the "separate compilation model".)
To get the full benefits of condition compilation, it's probably easier to get a program to help you than to
try and remember which files you've changed since you last compiled. (You could, of course, just
recompile every file that has a timestamp greater than the timestamp of the corresponding object file.) If
you're working with an integrated development environment (IDE) it may already take care of this for you.
If you're using command line tools, there's a nifty utility called make that comes with most *nix
distributions. Along with conditional compilation, it has several other nice features for programming, such
as allowing different compilations of your program -- for instance, if you have a version producing verbose
output for debugging.
Knowing the difference between the compilation phase and the link phase can make it easier to hunt for
bugs. Compiler errors are usually syntactic in nature -- a missing semicolon, an extra parenthesis. Linking
errors usually have to do with missing or multiple definitions. If you get an error that a function or variable
is defined multiple times from the linker, that's a good indication that the error is that two of your source
code files have the same function or variable.
Software Interrupt:
It is an interrupt generated within a processor by executing an instruction . Software interrupt are often
used to implement some specific functionality to get executed whose functionality will be in specified in
ISR.
SET II
RATING FACTOR
0. Phone Interview Questions
1. Why are you looking for new job?
2. What is your ideal job (looking for programming interest)
3. Are you eligible to work in the U.S without limitation?
4. Are you willing/able to travel?
5. Salary Requirements
6. What type of processors have you worked with?
7. What programming courses have you had? How well did you do?
8. Describe your C and/or programming background (was experience direct or team member did work). -
-- Pointers (difference between * &) &-gets address of a variable and *dereferences an address to get
Value?
- What is casting used for (tell compiler what size you expect it to use)?
- What is a structure (organizes data)?
- What is #define (substituted by compiler)?
- Range of a 16 bit variable (2^16-1 unsigned –32768 to 32767 signed)
0.9 Describe your electronics background/experience (was this direct experience or team member did work).
0.10 Explain the dept. Do you fit with that type of position?
0.11 Explain how your experience would apply to this structure.
0.12 Why do you want to work at TRW
1. Logic/Problem Solving
8
A. Dealership calls and indicates they have a vehicle; it is having a problem with setting SWA DTC’s. They
have replaced our module 3 times and the SWA sensor 3 times and the DTC is still setting. What should
you tell them to look for?
Answer: The wiring harness some sort of mechanical interface that allows sensor to slip.
B. In equation b_u16*c_u16/d_u16 provide mathematical proof that if b_u16 is less than d_u16 that result
fits in a_u16.
Answer: b/d<1 so something less than 1 multiplied by c is less than c.
C. Calculate area X (see problem 1 below).
Answer: see if knows the right questions to ask. Area of big piece of pie minus small one is
30/360*2*2*pi-30/360*1*1*pi.
2. Software Development
A. How have you managed requirements? What tools? What is the output of requirements analysis?
B. How have you documented software designs? What tools? What methodologies? Describe how a state
machine design works (do example on problem 2).
Answer: OO, SA/SD make sure they cover events of motor on and off for each state with 4 states full
on, full off, ramping off and ramping on.
State Machine. Design motor feedback simulator function that accepts a motor command and returns its
feedback. The motor feedback returns 0 volts when full on. 12 volts when full off. The feedback reduces
1 volt per second while ramping to full on state. Feedback increases 1 volt per second while ramping to a
full off state.
4. Hardware/microcontroller knowledge
A. What is Ohms Law? Have them do voltage divider (should be able to utilize Ohms Law to solve). If they
had it memorized, see if they can still derive it by applying Ohms law and solving simultaneous
equations?
Answer: V=IR. Vin=I*(R1+R2) and Vout=I*R1. Combine equations to get Vout=Vin*R1/(R1+R2).
Vin
R2
Vout
R1
Gnd
B. What is a microcontroller? How are floating operations done? What are the precautions that should be
used in setting up A/D channel (describe what A/D circuit looks like)?
9
Answer: I/O, PWM, A/D, Input Capture/Output Compare, SPI, RAM, ROM, NVRAM. Need to take care
in sample and hold times are matched with input impedance. If not, you will get cross talk between A/D
channels.
C. Describe how to use input capture/output compare peripherals.
Answer: time stamp rising and/or falling edges to calculate frequency. Toggle output pin at a certain rate.
5. C – Coding
A. How would you rank yourself in C 1 to 10 10 being best? What is the size of an int? Short int? Long?
Does code in 5) produce accurate results? Rewrite correct implementation.
Answer: Cast is in wrong place allowing overflow. A_u16=(U16)((U32)b_u16*c_u16)/d_u16;
Note: short int’s are 16 bits and long int’s are 32 bits. Does following produce accurate results?
unsigned short int a_u16, b_u16, c_u16, d_u16; /* Range of each is 0 to 0xffff */
a_u16 = (unsigned long int)(b_u16*c_u16)/d_u16;
B. Make a macro 4) that accepts two parameters and divides one by the other.
Answer: #define DIVIDE(x,y) ((x)/(y)). Make sure they understand need for all 3 sets of parenthesis
C. There is a 16 bit counter at address 0x8000 that counts up on each rising edge applied to a
microcontroller pin. Write a function to access this, save the first count read, then wait until counter gets
to 0 and then return that saved 1st count read. In other words, write a function to return the value of the
counter when the function is called; however, wait until the counter reaches 0 before returning
Answer:
Unsigned short int getCount() {
volatile unsigned short int *counterP; /*volatile req for making sure
optimizer does not assume the value can not change outside the thread
of execution */
counterP = (volatile unsigned short int *)0x8000;
counter=*counterP;
while (*counterP !=0);
return(counter);
ALSO ASK “What is wrong with this routine? In a realtime system?”
Answer: Could wait forever.
}
There is a 16 bit counter at address 0x8000 that counts up on each rising edge applied to a
microcontroller pin. Write a function to access this, save the first count read, then wait until counter gets
to 0 and then return that saved 1st count read. In other words, write a function to return the value of the
counter when the function is called; however, wait until the counter reaches 0 before returning.
B. Have you used Vector's Canape tool and if so how did you apply it? Describe the internal CAN special
function registers.
Answer: Canape is generally used as a data acquisition tool to look at variable values within the
software. It can also be used to modify parameters in the software real-time for testing or debugging
purposes. TRW uses it for trimming vehicles. It is not a bus analysis tool!
C. Do you have experience with CAN communications? if yes, Can you describe a general difference
between diagnostic frames and signal frames?
10
Answer: something along the lines of signal frames require no response from the receiving ECU where
diagnostic frames generally require a response from the ECU. Also, Signal frames are periodic where
functional messages are on-demand.
D. Do you know what a DBC file is?
Answer: this is the message database file that is used by the Vector generation tool and is provided to
suppliers by the U.S. OEM's to provide message requirements for a particular platform. If the person has
used CAN then they most likely will have used a DBC file for reference during development as our
application engineers do.
9. Controls
A. What is the slowest you can sample a 100 Hz signal and still get all its frequency content. Draw the
output of a 100 Hz sine wave sampled at a 100 Hz rate.
Answer: Greater than 200 Hz at 100 Hz you would sample a flat line.
B. Draw classic control system block diagram. What are the components of a PID controller? What is each
parts role in trying to control the temperature in a room.
Answer: Desired output minus measured output gives error which is used to adjust control and
measured feedback. Proportional to control gain. Derivative to control transient error due to door
opening. Integral to control steady state error of window draft.
C. What does equation (2) accomplish? Ask them to write code to accomplish (see notes below) Why
would you declare a global variable as static?
Answer: 1st order filter. Code expected:
Unsigned char eightBitFilter(unsigned char atodReading)
{
Static unsigned char lastAtoDReading=0; /* make sure initialized */
lastAtoDReading =
(unsigned short int)63*lastAtoDReading+atodReading)>>6;
Return(lastAtoDReading);
}
yn = 63/64*yn-1+1/64*input. Where input is the output of an 8 bit A/D reading? Write C routine that
accepts input and returns y[n].
Make sure: They use static to remember last result, they multiply first to preserve information, they cast
up to not overflow, they cast down to fit in result, and shift rather than divide is more efficient in some
microcontrollers. Static global variables only have file visibility.
11