C Interview Questions
C Interview Questions
C Interview Questions
C Language Embedded C
A type of high level language. Nothing but an extension of C.
The source code format depends upon the
Has a free-format of program coding. type of microprocessor/ microcontroller
that is used.
Optimization is normal. High level of optimization.
An Operating system is essential to Can work with or without an Operating
function. system.
Used for microcontroller/ microprocessor
Used for desktop applications.
applications.
Does not bother about memory Uses limited resources.
resources. Hence consider memory allocation of the
i.e., use entire memory available in CPU. embedded processor.
C programs run in console. They run in realtime constraints.
Hence see the output through desktop Hence output is not available in OS
Directly or indirectly support other
Supports only required processor of the
various programming languages during
application.
application.
Input can be given to the program while Only the pre-defined input can be given to
it is running. the running program.
Requires compilers of Embedded C.
C compilers are OS dependent.
These compilers in turn enable access to
i.e, run the ram directly from OS
all resources of the embedded system.
terminal.
Hence OS independent.
Some of the examples of Applications:
Some of the examples of real-time
logical programs, system software
Applications: DVD, TV,Digital camera.
programs.
Q. What is job of preprocessor, compiler, assembler and linker ?
The preprocessor commands are processed and expanded by the preprocessor before actual
compilation.
After preprocessing, the compiler takes the output of the preprocessor and the source code, and
generates assembly code.
Once compiler completes its work, the assembler takes the assembly code and produces an
assembly listing with offsets and generate object files.
The linker combines object files or libraries and produces a single executable file. It also
resolves references to external symbols, assigns final addresses to functions and variables, and
revises code and data to reflect new addresses.
Q. What is preprocessor ?
Preprocessor is a Program That processes its input data to produce output that is used as input to
another program. The output is said to be a pre processed form of the input data, which is often used by
some subsequent programs like compilers. The amount and kind of processing done depends on the
nature of the pre processor.
Some Pre-processors Are Only Capable Of Performing Relatively Simple Textual Substitutions And
Macro Expansions, while others have the power of full-fledged programming languages.
Q. What Is Pass By Value And Pass By Reference? How Are Structure Passed As Arguments?
Answer :
The parameter to a function can be a copy of a value that is represented by variable or can be a
reference to a memory space that stores value of variable. The former is referred to as pass by value
and the latter is referred to as pass by reference. The difference is that when parameters are passed by
value the changes made to the variable value within the function is not reflected in the caller function,
but when passed as reference changes are reflected outside the called function. The structures are
always passed by reference.
Q. What Is The Volatile Keyword Used For?
Answer :
The volatile keyword is used to represent variables that point to memory in other mapped devices. In
such a case the value of the variable can be changed outside of a program. The compiler does not do
additional optimizations to the code if there is volatile keyword.
Q. What Does Malloc Do? What Will Happen If We Have A Statement Like Malloc(sizeof(0));
Answer :
Malloc is the function that is used for dynamically allocating memory to the different variables. The
malloc returns a memory pointer of void type (void *). The statement malloc(sizeof(0)) returns a valid
integer pointer because sizeof(0) represents the size of memory taken up by the integer value of 0. The
memory allocated by memory is not automatically cleaned up by the compiler after execution of the
functions and should be cleaned up by the programmer using the free() function.
Method 1 :-
while(1)
{
}
Method 2 :-
for(;;)
{
Method 3 :-
Loop:
goto Loop
Q. Which bit wise operator is suitable for checking whether a particular bit is on or off?
Ans :- "Bitwise And" (&) is used to check if any particular bit is set or not. To check whether 5'th bit is
set we can write like this
bit = (byte >> 4) & 0x01;
Here, shifting byte by 4 position means taking 5'th bit to first position and "Bitwise And" will get the
value in 0 or 1.
Q. When Should We Use The Recursion Function? Mention What Happens When Recursion
Functions Are Declared Inline?
Answer :
Recursion function should be used when we are aware of the number of recursive calls is not excessive.
Inline functions property says whenever it will call, it will copy the full definition of the function.
Recursive functions declared as inline, creates the burden for the compiler's execution.
Q. What Is Pass By Value And Pass By Reference? How Are Structure Passed As Arguments?
Answer :
The parameter to a function can be a copy of a value that is represented by variable or can be a
reference to a memory space that stores value of variable. The former is referred to as pass by value
and the latter is referred to as pass by reference. The difference is that when parameters are passed by
value the changes made to the variable value within the function is not reflected in the caller function,
but when passed as reference changes are reflected outside the called function. The structures are
always passed by reference.
Q. What Does Malloc Do? What Will Happen If We Have A Statement Like Malloc(sizeof(0));
Answer :
Malloc is the function that is used for dynamically allocating memory to the different variables. The
malloc returns a memory pointer of void type (void *). The statement malloc(sizeof(0)) returns a valid
integer pointer because sizeof(0) represents the size of memory taken up by the integer value of 0. The
memory allocated by memory is not automatically cleaned up by the compiler after execution of the
functions and should be cleaned up by the programmer using the free() function.