100 Embedded C Interview Questions Your Interviewer Might Ask AticleWorld PDF
100 Embedded C Interview Questions Your Interviewer Might Ask AticleWorld PDF
com/)
! (https://www.facebook.com/Aticleworld-602608163238897/)
" (https://www.linkedin.com/in/amlendra-kumar-bb3b2096/)
+ (https://plus.google.com/u/0/103635803767777469765)
$ (https://twitter.com/aticleworld) %
& MENU
,,
33 (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-
2/#COMMENTS)
In my previous post, I have created a collection of “c interview questions” that is liked by many people. I have also got the
response to create a list of interview questions on “embedded c”. So here I have tried to create some collection of
embedded c interview questions that might be asked by your interviewer.
In another side volatile prevent from any compiler optimization and says that the value of the object can be changed by
something that is beyond the control of the program and so that compiler will not make any assumption about the object.
e.g,
volatile int a;
When the compiler sees the above declaration then it avoids to make any assumption regarding the “a” and in every
iteration read the value from the address which is assigned to the variable.
After using the volatile keyword, you will get the proper value whenever you are accessing the ports but still here is one
more problem because the pointer is not const type so it might be your program change the pointing address of the
pointer. So we have to create a constant pointer with volatile keyword.
Syntax of declaration,
unit32_t GetRecvData()
{
//Code to recv data
while (((*pStatusReg) & COM_STATUS_BIT) == 0)
{
// Wait until flag does not set
}
return RecvData;
}
ISR(void)
{
giFlag = 1;
}
int main(void)
{
while (!giFlag)
{
//do some work
}
return 0;
}
What is ISR?
An ISR refers to the Interrupt Service Routines. These are procedures stored at specific memory addresses which are called
when a certain type of interrupt occurs. The Cortex-M processors family has the NVIC that manage the execution of the
interrupt.
In the above line, we have already read that the ISR is not called by the code, so there is no calling code to read the
returned values of the ISR. It is the reason that an ISR is not returned any value.
The Cortex-M processors have the very low interrupt latency. In below table, I have mentioned, Interrupt latency of Cortex-
M processors with zero wait state memory systems.
Cortex-M0 16
Cortex-M0+ 15
Cortex-M3 12
Cortex-M4 12
Cortex-M7 12
The interval between the two signals (interrupt latency) may be easily read from the instrument.
So using the proper selection of platform and processor we can easily reduce the interrupt latency. We can also reduce the
interrupt latency by making the ISR shorter and avoid to calling a function within the ISR.
(https://click.linksynergy.com/deeplink?
id=UajS5soDmWY&mid=39197&murl=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fwww.udemy.com%2Fmastering-microcontroller-with-
peripheral-driver-development%2F)
The Cortex-M3 and Cortex-M4 processors the NVIC supports up to 240 interrupt inputs, with 8 up to 256 programmable
priority levels
One important point also needs to remember that function which is called from the ISR should be re-entrant. If the called
function is not re-entrant, it could create the issues.
For example,
C Programming Language, 2nd Edition (https://aax-us-east.amazon- Making Embedded Systems: Design Patterns for Grea… (https://aax-us-
adsystem.com/x/c/QhI8hDUxdOncJ6OQu6mi- east.amazon-adsystem.com/x/c/QhI8hDUxdOncJ6OQu6mi-
YkAAAFrzBID6AEAAAFKAZ9lcWc/https://www.amazon.com/Programming- YkAAAFrzBID6AEAAAFKAZ9lcWc/https://www.amazon.com/Making-
$60.30 $67.00
Language-2nd-Brian- $30.40 $39.99
Embedded-Systems-Patterns-
Kernighan/dp/0131103628/ref=sm_n_se_dkp_VN_pr_sea_0_0?
(615) Software/dp/1449302149/ref=sm_n_se_dkp_VN_pr_sea_0_1?
(54)
adId=0131103628&creativeASIN=0131103628&linkId=0e96fb5178b3c0d08d9… adId=1449302149&creativeASIN=1449302149&linkId=0e96fb5178b3c0d08d9…
20&linkCode=w42&ref- 20&linkCode=w42&ref-
refURL=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Faticleworld.com%2Fembedded-c-interview- refURL=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Faticleworld.com%2Fembedded-c-interview-
questions-2%2F&slotNum=1&imprToken=PacoyqB5K.- questions-2%2F&slotNum=1&imprToken=PacoyqB5K.-
KajXbujSXGg&adType=smart&adMode=search&adFormat=grid&impressionTi… KajXbujSXGg&adType=smart&adMode=search&adFormat=grid&impressionTi…
Embedded C Programming: Techniques and Applicatio… (https://aax-us- Test Driven Development for Embedded C (Pragmat… (https://aax-us-
east.amazon-adsystem.com/x/c/QhI8hDUxdOncJ6OQu6mi- east.amazon-adsystem.com/x/c/QhI8hDUxdOncJ6OQu6mi-
YkAAAFrzBID6AEAAAFKAZ9lcWc/https://www.amazon.com/Embedded- YkAAAFrzBID6AEAAAFKAZ9lcWc/https://www.amazon.com/Driven-
$50.35 $59.95
Programming-Techniques-Applications- $26.60 $34.95
Development-Embedded-Pragmatic-
MCUS/dp/0128013141/ref=sm_n_se_dkp_VN_pr_sea_1_0?
(3) Programmers/dp/193435662X/ref=sm_n_se_dkp_VN_pr_sea_1_1?
(32)
adId=0128013141&creativeASIN=0128013141&linkId=0e96fb5178b3c0d08d9… adId=193435662X&creativeASIN=193435662X&linkId=0e96fb5178b3c0d08d…
Ads by Amazon (https://aax-us-east.amazon-adsystem.com/x/c/QhI8hDUxdOncJ6OQu6mi-YkAAAFrzBID6AEAAAFKAZ9lcWc/https://affiliate-program.amazon.com/home/ads/ref=sm_n_se_dkp_VN_logo?
adId=logo&creativeASIN=logo&linkId=0e96fb5178b3c0d08d9383a937f63edd&tag=aticleworld02-20&linkCode=w42&ref-refURL=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Faticleworld.com%2Fembedded-c-interview-questions-
2%2F&slotNum=1&imprToken=PacoyqB5K.-KajXbujSXGg&adType=smart&adMode=search&adFormat=grid&impressionTimestamp=1562496864063&ac-ms-src=nsa-ads&cid=nsa-ads)
(https://aax-us-east.amazon-adsystem.com/x/c/QhI8hDUxdOncJ6OQu6mi-YkAAAFrzBID6AEAAAFKAZ9lcWc/https://www.amazon.com/adprefs/ref=sm_n_se_dkp_VN_ac?
tag=aticleworld02-20&linkCode=w42)
Infinite loops often arise in embedded systems. How do you code an infinite loop in C?
In embedded systems, infinite loops are generally used. If I talked about a small program to control a led through the
switch, in that scenario an infinite loop will be required if we are not going through the interrupt.
There are the different way to create an infinite loop, here I am mentioning some methods.
Method 1:
while(1)
{
// task
}
Method 2:
for(;;)
{
// task
}
Method 3:
Loop:
goto Loop;
RISC CISC
Acronym It stands for ‘Reduced Instruction Set It stands for ‘Complex Instruction Set
Computer’. Computer’.
Definition The RISC processors have a smaller set of The CISC processors have a larger set of
instructions with few addressing nodes. instructions with many addressing nodes.
Memory unit It has no memory unit and uses a It has a memory unit to implement
separate hardware to implement complex instructions.
instructions.
Calculations The calculations are faster and precise. The calculations are slow and precise.
External memory It does not require external memory for It requires external memory for
calculations. calculations.
Pipelining Pipelining does function correctly. Pipelining does not function correctly.
Code expansion Code expansion can be a problem. Code expansion is not a problem.
If stack overflow occurs, the program can crash or you can say that segmentation fault that is the result of the stack
overflow.
The important difference between the I2C and SPI communication protocol.
I2C support half duplex while SPI is the full duplex communication.
I2C requires only two wire for communication while SPI requires three or four wire for communication (depends on
requirement).
I2C is slower as compared to the SPI communication.
I2C draws more power than SPI.
I2C is less susceptible to noise than SPI.
I2C is cheaper to implement than the SPI communication protocol.
I2C work on wire and logic and it has a pull-up resistor while there is no requirement of pull-up resistor in case of the SPI.
In I2C communication we get the acknowledgment bit after each byte, it is not supported by the SPI communication protocol.
I2C ensures that data sent is received by the slave device while SPI does not verify that data is received correctly.
I2C support the multi-master communication while multi-master communication is not supported by the SPI.
One great difference between I2C and SPI is that I2C supports multiple devices on the same bus without any additional select
lines (work on the basis of device address) while SPI requires additional signal (slave select lines) lines to manage multiple
devices on the same bus.
I2C supports arbitration while SPI does not support the arbitration.
I2C support the clock stretching while SPI does not support the clock stretching.
I2C can be locked up by one device that fails to release the communication bus.
I2C has some extra overhead due to start and stop bits.
There is no common clock signal between the sender and Communication is done by a shared clock.
receivers.
Sends 1 byte or character at a time. Sends data in the form of blocks or frames.
A start and stop bit used for the data synchronization. A shared clock is used for the data synchronization.
Economical Costly
Bit rate is the number of bits per second. Baud rate is the number of signal units per second.
It determines the number of bits traveled per second. It determines how many times the state of a signal is changing.
Cannot determine the bandwidth. It can determine how much bandwidth is required to send the
signal.
This term generally used to describe the processor efficiency. This term generally used to describe the data transmission over
the channel.
Bit rate = baud rate x the number of bits per signal unit Baud rate = bit rate / the number of bits per signal unit
Generally, the segmentation fault occurs when a program tried to access a memory location that it is not allowed to access
or tried to access a memory location in a way that is not allowed (tried to access read-only memory).
Non-existent address.
Unaligned access.
Paging errors
Primarily size of integer depends on the type of the compiler which has written by compiler writer for the underlying
processor. You can see compilers merrily changing the size of integer according to convenience and underlying
architectures. So it is my recommendation use the C99 integer data types ( uin8_t, uin16_t, uin32_t ..) in place of standard int.
(https://shareasale.com/r.cfm?b=898512&u=1658724&m=26748&urllink=&afftrack=)
A signed integer can store the positive and negative value both but beside it unsigned integer can only store the positive
value.
The range of nonnegative values of a signed integer type is a sub-range of the corresponding unsigned integer type.
For example,
typedef:
The C language provides a very important keyword typedef (https://aticleworld.com/typedef-in-c/) for defining a
new name for existing types. The typedef is the compiler directive mainly use with user-defined data types (structure, union
or enum) to reduce their complexity and increase the code readability and portability.
Syntax,
typedef type NewTypeName;
Now UnsignedInt is a new type and using it, we can create a variable of unsigned int.
UnsignedInt Mydata;
In above example, Mydata is variable of unsigned int.
Note: A typedef creates synonyms or a new name for existing types it does not create new types.
A macro is a pre-processor directive and it replaces the value before compiling the code.One of the major problem with the
macro that there is no type checking. Generally, the macro is used to create the alias, in C language macro is also used as a
file guard.
Syntax,
#define Value 10
Now Value becomes 10, in your program, you can use the Value in place of the 10.
An enumeration increases the readability of the code and easy to debug in comparison of symbolic constant (macro).
The most important thing about the enum is that it follows the scope rule and compiler automatic assign the value to its
member constant.
Note: A variable of enumeration type stores one of the values of the enumeration list defined by that type.
Syntax of enum,
enum Enumeration_Tag { Enumeration_List };
Example,
enum FLASH_ERROR { DEFRAGMENT_ERROR, BUS_ERROR};.
Clearing a Bits
Bitwise AND operator (&) use to clear a bit of integral data type. “AND” of two bits is always zero if any one of them is zero.To
clear the nth bit, first, you need to invert the string of bits then AND it with the number.
Checking a Bits
To check the nth bit, shift the ‘1’ nth position toward the left and then “AND” it with the number.
Toggling a Bits
Bitwise XOR (^) operator use to toggle the bit of an integral data type. To toggle the nth bit shift the ‘1’ nth position toward
the left and “XOR” it.
Write a program swap two numbers without using the third variable?
Let’s assume a, b two numbers, there are a lot of methods two swap two number without using the third variable.
#include <stdio.h>
int main()
{
int a = 10, b = 5;
return 0;
}
#include <stdio.h>
int main()
{
int a = 10, b = 5;
return 0;
}
Padding has increased the performance of the processor at the penalty of memory.In structure or union data members
aligned as per the size of the highest bytes member to prevent from the penalty of performance.
Note: Alignment of data types mandated by the processor architecture, not by language.
Big-endian
The most significant byte of data stored at the lowest memory address.
Little-endian
The least significant byte of data stored at the lowest memory address.
Method 1:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main(void)
{
uint32_t u32RawData;
uint8_t *pu8CheckData;
u32RawData = 0x11223344; //Assign data
return 0;
}
Method 2:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
typedef union
{
}RawData;
int main(void)
{
RawData uCheckEndianess;
uCheckEndianess.u32RawData = 0x11223344; //assign the value
return 0;
}
Method 1:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main()
{
uint32_t u32CheckData = 0x11223344;
uint32_t u32ResultData =0;
u32ResultData = ChangeEndianness(u32CheckData); //swap the data
printf("0x%x\n",u32ResultData);
u32CheckData = u32ResultData;
u32ResultData = ChangeEndianness(u32CheckData);//again swap the data
printf("0x%x\n",u32ResultData);
return 0;
}
Static Allocation means, an object has external or internal linkage or declared with static storage-class. It’s initialized only
once, prior to program startup and its lifetime is throughout the execution of the program. A global and static variable is an
example of static memory allocation.
In C language, there are a lot of library functions (malloc, calloc, or realloc,..) which are used to allocate memory
dynamically. One of the problems with dynamically allocated memory i (https://aticleworld.com/dynamic-
memory-allocation-in-c/)
memory-allocation-in-c/)s that it is not destroyed by the compiler itself that means it is the responsibility of the user to
deallocate the allocated memory.
When we allocate the memory using the memory management function, they return a pointer to the allocated memory
block and the returned pointer is pointing to the beginning address of the memory block. If there is no space available,
these functions return a null pointer.
int main ()
{
/* Do some work */
Note: once you allocate a memory than allocated memory does not allocate to another program or process until it gets
free.
In C language,calloc function initialize the all allocated space bits with zero but malloc does not initialize the allocated
memory. These both function also has a difference regarding their number of arguments, malloc take one argument but
calloc takes two.
The calloc function first deallocates the old object and allocates again with newly specified size. If the new size is lesser to
the old size, the contents of the newly allocated memory will be same as prior but if any bytes in the newly created object
goes beyond the old size, the values of the exceeded size will be indeterminate.
Syntax:
void *realloc(void *ptr, size_t size);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *pcBuffer = NULL;
/* Initial memory allocation */
pcBuffer = malloc(8);
strcpy(pcBuffer, "aticle");
printf("pcBuffer = %s\n", pcBuffer);
/* Reallocating memory */
pcBuffer = realloc(pcBuffer, 15);
strcat(pcBuffer, "world");
printf("pcBuffer = %s\n", pcBuffer);
return 0;
}
Output:
pcBuffer = aticle
pcBuffer = aticleworld
Note: It should be used for dynamically allocated memory but if a pointer is a null pointer, realloc behaves like the malloc
function.
The external fragmentation is due to the small free blocks of memory (small memory hole) that is available on the free list
but program not able to use it. There are different types of free list allocation algorithms that used the free memory block
efficiently.
To understand the external fragmentation, consider a scenario where a program has 3 contiguous blocks of memory and
the user frees the middle block of memory. In that scenario, you will not get a memory, if the required block of memory is
larger than a single block of memory (but smaller or equal to the aggregate of the block of memory).
The internal fragmentation is wasted of memory that is allocated for rounding up the allocated memory and in
bookkeeping (infrastructure), the bookkeeping is used to keep the information of the allocated memory.
Whenever we called the malloc function then it reserves some extra bytes (depend on implementation and system) for
bookkeeping. This extra byte is reserved for each call of malloc and become a cause of the internal fragmentation.
char *acBuffer[100];
int main()
{
int iLoop = 0;
while(iLoop < 100)
{
acBuffer[iLoop ] = malloc(8);
++iLoop;
Whenever we call the free function and pass the pointer that is pointing to allocated memory, the free function gets the
bookkeeping information and release the allocated memory. Anyhow if you or your program change the value of the
pointer that is pointing to the allocated address, the calling of free function give the undefined result.
For example,
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *pcBuffer = NULL;
pcBuffer = malloc(sizeof(char) * 16); //Allocate the memory
return 0;
}
In the other word, we can say, a function pointer is a type of pointer that store the address of a function and these pointed
function can be invoked by function pointer in a program whenever required.
The declaration of a pointer to a function is similar to the declaration of a function. That means function pointer also
requires a return type, declaration name, and argument list. One thing that you need to remember here is, whenever you
declare the function pointer in the program then declaration name is preceded by the * (Asterisk) symbol and enclosed in
parenthesis.
For example,
For the better understanding, let’s take an example to describe the declaration of a function pointer in c.
e.g,
void ( *pfDisplayMessage) (const char *);
In above expression, pfDisplayMessage is a pointer to a function taking one argument, const char *, and returns void.
When we declare a pointer to function in c then there is a lot of importance of the bracket. If in the above example, I
remove the bracket, then the meaning of the above expression will be change and it becomes void *pfDisplayMessage
(const char *). It is a declaration of a function which takes the const character pointer as arguments and returns void pointer.
int main()
{
int x = -15;
x = x << 1;
printf("%d\n", x);
}
Output:
undefined behavior.
int main()
{
int x = -30;
x = x >> 1;
printf("%d\n", x);
}
Output:
implementation-defined.
According to C standard, the pointer to void shall have the same representation and alignment requirements as a pointer to
a character type.A void pointer declaration is similar to the normal pointer, but the difference is that instead of data types we
use the void keyword.
Syntax:
void * Pointer_Name;
Using the void pointer we can create a generic function that can take arguments of any data type. The memcpy and memmove
library function are the best examples of the generic function, using these function we can copy the data from the source to
destination.
e.g.
void * memcpy ( void * dst, const void * src, size_t num );
We have already know that void pointer can be converted to another data type that is the reason malloc, calloc or realloc
library function return void *. Due to the void * these functions are used to allocate memory to any data type.
Using the void * we can create a generic linked list.For more information see this link: How to create generic Link List.
For example,
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *piData = NULL;
return 0;
ELEGOO UNO Project Super Starter Kit with Tu… (https://aax-us-east.amazon- ARDUINO UNO R3 [A000066] (https://aax-us-east.amazon-
adsystem.com/x/c/Qs0FJuPHnq4rfJyQozucEksAAAFrzBID1AEAAAFKAULY9… adsystem.com/x/c/Qs0FJuPHnq4rfJyQozucEksAAAFrzBID1AEAAAFKAULY9…
Project-Tutorial-Controller- A000066-ARDUINO-UNO-
$35.00
Projects/dp/B01D8KOZF4/ref=sm_n_se_dkp_VN_pr_sea_0_0? $20.00
R3/dp/B008GRTSV6/ref=sm_n_se_dkp_VN_pr_sea_0_1?
adId=B01D8KOZF4&creativeASIN=B01D8KOZF4&linkId=49aef9aa83f7c2895…
(958) adId=B008GRTSV6&creativeASIN=B008GRTSV6&linkId=49aef9aa83f7c2895…
(732)
20&linkCode=w42&ref- 20&linkCode=w42&ref-
refURL=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Faticleworld.com%2Fembedded-c-interview- refURL=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Faticleworld.com%2Fembedded-c-interview-
questions- questions-
2%2F&slotNum=2&imprToken=NXPhkADQ7syylOaNyXKzfg&adType=smart&… 2%2F&slotNum=2&imprToken=NXPhkADQ7syylOaNyXKzfg&adType=smart&…
Elegoo EL-KIT-008 Mega 2560 Project The Most C… (https://aax-us- Arduino Starter Kit - English Official Kit With 170 Page… (https://aax-us-
east.amazon- east.amazon-
adsystem.com/x/c/Qs0FJuPHnq4rfJyQozucEksAAAFrzBID1AEAAAFKAULY9… adsystem.com/x/c/Qs0FJuPHnq4rfJyQozucEksAAAFrzBID1AEAAAFKAULY9…
$59.99
KIT-008-Project-Complete-Ultimate- $70.00
Starter-Kit-English-
Tutorial/dp/B01EWNUUUA/ref=sm_n_se_dkp_VN_pr_sea_1_0?
(544) Official/dp/B009UKZV0A/ref=sm_n_se_dkp_VN_pr_sea_1_1?
(760)
adId=B01EWNUUUA&creativeASIN=B01EWNUUUA&linkId=49aef9aa83f7c2… adId=B009UKZV0A&creativeASIN=B009UKZV0A&linkId=49aef9aa83f7c2895…
Ads by Amazon (https://aax-us-east.amazon-adsystem.com/x/c/Qs0FJuPHnq4rfJyQozucEksAAAFrzBID1AEAAAFKAULY9zo/https://affiliate-program.amazon.com/home/ads/ref=sm_n_se_dkp_VN_logo?
adId=logo&creativeASIN=logo&linkId=49aef9aa83f7c2895f4870b99f96dd36&tag=aticleworld02-20&linkCode=w42&ref-refURL=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Faticleworld.com%2Fembedded-c-interview-questions-
2%2F&slotNum=2&imprToken=NXPhkADQ7syylOaNyXKzfg&adType=smart&adMode=search&adFormat=grid&impressionTimestamp=1562496863492&ac-ms-src=nsa-ads&cid=nsa-ads)
(https://aax-us-east.amazon-adsystem.com/x/c/Qs0FJuPHnq4rfJyQozucEksAAAFrzBID1AEAAAFKAULY9zo/https://www.amazon.com/adprefs/ref=sm_n_se_dkp_VN_ac?
tag=aticleworld02-20&linkCode=w42)
In the other word, we can say every pointer in programming languages (https://aticleworld.com/pointers-in-
c/) that are not initialized either by the compiler or programmer begins as a wild pointer.
Syntax,
int *piData; //piData is wild pointer.
If you are reading a flash memory byte by bytes through the character pointer then here you have to use the post-
increment, either you will skip the first byte of the data. Because we already know that in case of pre-increment pointing
address will be increment first and after that, you will read the value.
#include <stdio.h>
int main(void)
{
pcData = acData;
printf("%c ",*++pcData);
return 0;
}
#include <stdio.h>
int main(void)
{
pcData = acData;
printf("%c ",*pcData++);
return 0;
}
Besides that, when we need a loop or just only need to increment the operand then pre-increment is far better than post-
increment because in case of post increment compiler may have created a copy of old data which takes extra time. This is
not 100% true because nowadays compiler is so smart and they are optimizing the code in a way that makes no difference
between pre and post-increment. So it is my advice, if post-increment is not necessary then you have to use the pre-
increment.
Note: Generally post-increment is used with array subscript and pointers to read the data, otherwise if not necessary then
use pre in place of post-increment.Some compiler also mentioned that to avoid to use post-increment in looping condition.
iLoop = 0.
#include <stdio.h>
int main(void)
{
int aiData[5] = {100,200,300,400,500};
++*piData;
return 0;
}
Explanation:
In the above example, two operators are involved and both have the same precedence with a right to left associativity. So
the above expression ++*p is equivalent to ++ (*p). In another word, we can say it is pre-increment of value and output is 101,
200, 101.
#include <stdio.h>
int main(void)
{
int aiData[5] = {100,200,30,40,50};
*++piData;
return 0;
}
Explanation:
In the above example, two operators are involved and both have the same precedence with the right to left associativity. So
the above expression *++p is equivalent to *(++p). In another word you can say it is pre-increment of address and output is
100, 200,200.
Syntax
const DataType Identifier = Value;
e.g.
const int iData = 0
Constant pointer:
Let’s see the below example code when you will compile the below code get the compiler error.
#include<stdio.h>
int main(void)
{
int var1 = 10, var2 = 20;
printf("%d\n", *ptr);
return 0;
}
In this scenario the value of pointed address is constant that means we can not change the value of the address that is
pointed by the pointer.
#include<stdio.h>
int main(void)
{
int var1 = 100;
// pointer to constant integer
const int* ptr = &var1;
printf("%d\n", *ptr);
return 0;
}
A static variable only initializes once, so a variable declared static within the body of a function maintains its prior value
between function invocations.
A global variable with static keyword has an internal linkage, so it only accesses within the translation unit (.c). It is not
accessible by another translation unit. The static keyword protects your variable to access from another translation unit.
By default in C language, linkage of the function is external that it means it is accessible by the same or another translation
unit. With the help of the static keyword, we can make the scope of the function local, it only accesses by the translation unit
within it is declared.
So global variable can be accessed outside of the file but the static global variable only accesses within the file in which it
is declared.
Declaration of variable in c
A variable declaration only provides sureness to the compiler at the compile time that variable
(https://aticleworld.com/variable-in-c-language/) exists with the given type and name, so that compiler proceeds
for further compilation without needing all detail of this variable. In C language, when we declare a variable, then we only
give the information to the compiler, but there is no memory reserve for it. It is only a reference, through which we only
assure to the compiler that this variable may be defined within the function or outside of the function.
Note: We can declare a variable multiple time but defined only once.
eg,
extern int data;
extern int foo(int, int);
int fun(int, char); // extern can be omitted for function declarations
Definition of variable in c
The definition is action to allocate storage to the variable. In another word, we can say that variable definition is the way to
say the compiler where and how much to create the storage for the variable generally definition and declaration occur at
the same time but not almost.
eg,
int data;
int foo(int, int) { }
Note: When you define a variable then there is no need to declare it but vice versa is not applicable.
What is the difference between pass by value by reference in c and pass by reference in c?
Pass By Value:
In this method value of the variable is passed. Changes made to formal will not affect the actual parameters.
Different memory locations will be created for both variables.
Here there will be temporary variable created in the function stack which does not affect the original variable.
Pass By Reference :
Aticleworld invites you to try skillshare (Unlimited Access to over 20,000 classes) Premium free for 2 months
months..
(//skillshare.evyy.net/c/1192901/351694/4650)
for example,
Advantages:-
1) It saves the function calling overhead.
2) It also saves the overhead of variables push/pop on the stack, while function calling.
3) It also saves the overhead of return call from a function.
4) It increases locality of reference by utilizing instruction cache.
5) After inlining compiler can also apply intraprocedural optimization if specified. This is the most important one, in this way
compiler can now focus on dead code elimination, can give more stress on branch prediction, induction variable
elimination etc..
Consider the two statements and find the difference between them?
struct sStudentInfo {
char Name[12];
int Age;
float Weight;
int RollNumber;
};
statement 1
STUDENT_INFO p1, p2;
statement 2
studentInfo q1, q2;
Both statements looking same but actually, both are different to each other.
Statement 1 will be expanded to struct sStudentInfo * p1, p2. It means that p1 is a pointer to struct sStudentInfo but p2 is a
variable of struct sStudentInfo.
Here, I have mentioned some more embedded c interview questions for you. If you know, please write in the
comment box. Might be your comment helpful for others.
Memory Layout of C
program
aticleworld.com
100 c interview
questions, your
interviewer might ask
aticleworld.com
Dynamic memory
allocation in C, a brief
introduction
aticleworld.com
Function Pointer in C
Struct
aticleworld.com
Difference between
I2C and SPI ( I2C vs
SPI ), you should…
aticleworld.com
15 Common mistakes
with memory
allocation, you…
aticleworld.com
Const QualiKer in C
Language
aticleworld.com
Function pointer in c,
a detail guide
aticleworld.com
Ad
1. C Embedded Interview Questions
2. Software Coding
3. Answer Interview Job Question
Share this:
(https://aticleworld.com/embedded-c-interview-questions-2/?share=facebook&nb=1)
(https://aticleworld.com/embedded-c-interview-questions-2/?share=linkedin&nb=1)
(https://aticleworld.com/embedded-c-interview-questions-2/?share=twitter&nb=1)
(https://aticleworld.com/embedded-c-interview-questions-2/?share=reddit&nb=1)
(https://aticleworld.com/embedded-c-interview-questions-2/?share=tumblr&nb=1)
(https://aticleworld.com/embedded-c-interview-questions-2/?share=pinterest&nb=1)
(https://aticleworld.com/embedded-c-interview-questions-2/?share=email&nb=1)
(https://aticleworld.com/embedded-c-interview-questions-2/?share=jetpack-whatsapp&nb=1)
) WEBSITE (HTTPS://ATICLEWORLD.COM/)
(https://aticleworld.com/bit-field-in-c/)
(https://aticleworld.com/steps-to-learn-c-
33 comments
Niraj
APRIL 6, 2018 AT 3:32 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-808)
Const does not mean that value of variable can not modified, it only mean the variable can not occur at left side of a assignment
operator. I can modify the value of const variable by first initialising its address into a pointer and then using pointer its value can be
changed.
REPLY
Amlendra
const is just an qualifier. If you will try to change the value of const through the pointer, then behavior is undefined. According to C
standard “If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified
type, the behavior is undefined.”. So it is not recommended to change the value of constant variable..
REPLY
alok
APRIL 7, 2018 AT 10:25 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-810)
REPLY
Amlendra
APRIL 7, 2018 AT 10:28 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-811)
REPLY
Pooja
APRIL 7, 2018 AT 10:43 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-812)
Somebody asked me a question to multiply a integer number with 3.5 using bitwise operation. Can you give me answer of this question.
REPLY
Amlendra
APRIL 7, 2018 AT 10:47 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-813)
You can simply multiply an integer number with 3.5 using the shifting operators.
REPLY
Dhiraj Jadhav
JUNE 6, 2018 AT 4:02 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-997)
Volatile Memory is a type of memory in which data contained in the memory is lost whenever the power is turned off. RAM or Random
Access Memory is an example of a volatile memory. … ROM is an example of the Non-volatile memory as once the user turns off your
computer then content remains intact and will not get lost.
REPLY
Amlendra (https://aticleworld.com/)
JUNE 7, 2018 AT 2:20 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-998)
REPLY
Naman
JUNE 8, 2018 AT 12:24 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-999)
Watchdog timer is a special type of timer used to monitor any sofware failure in microcontroller.
Software failure i.e if system hangs due to some problem and does not able to execute the code than watchdog timer has the capability
to generate a power reset so that microcontroller starts running again .
It is different from normal timer because normal timer can only generate interrupt or any signal but not power reset.
It is important in microcontroller applications because in most of the applications user does not have any access on controller so if some
problem occurs ,only watchdog timer can save it from system failure.
REPLY
Amlendra (https://aticleworld.com/)
JUNE 10, 2018 AT 7:43 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1001)
REPLY
suresh.pv
JULY 4, 2018 AT 1:01 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1021)
very very very good and usefull information for embedded students and employes.
REPLY
Amlendra (https://aticleworld.com/)
JULY 4, 2018 AT 2:31 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1022)
REPLY
Anushree
AUGUST 3, 2018 AT 11:59 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1055)
I just completed reading 100 Embedded C interview questions. I am able to brush up many things. Really really good source of questions
and answers. Thanks a lot
REPLY
Amlendra (https://aticleworld.com/)
AUGUST 3, 2018 AT 11:05 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1058)
REPLY
REPLY
Amlendra (https://aticleworld.com/)
SEPTEMBER 4, 2018 AT 10:18 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1116)
thank you.
REPLY
alasklany
SEPTEMBER 18, 2018 AT 7:05 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1166)
REPLY
Amlendra (https://aticleworld.com/)
SEPTEMBER 19, 2018 AT 2:28 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1168)
Thanks.
REPLY
surya
OCTOBER 12, 2018 AT 8:47 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1206)
can you same that how to write a c program to know the processor(not compiler ) is 32 bit or 64 bit
REPLY
surya
OCTOBER 12, 2018 AT 8:56 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1207)
REPLY
Kalai
NOVEMBER 7, 2018 AT 10:57 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1271)
We can not reduce the interrupt latency by making the ISR shorter and avoid to calling a function within the ISR.
Basically Interrupt latency is time taken for switching from interrupted task to executing first instruction of ISR. So even though you have
shorter ISR, Interrupt latency can not be reduced.
REPLY
Nalini
NOVEMBER 13, 2018 AT 8:40 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1287)
REPLY
Dj1
NOVEMBER 14, 2018 AT 10:53 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1288)
REPLY
arunprasad
NOVEMBER 27, 2018 AT 2:30 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1366)
hai sir ,i need a favor,can you please upload a tutorial for interrupt for embedded micro-controllers.
REPLY
Amlendra (https://aticleworld.com/)
NOVEMBER 28, 2018 AT 11:54 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-1375)
REPLY
REPLY
Himabindu
FEBRUARY 28, 2019 AT 11:27 AM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-2285)
Just wow, amazing article. I could able to brush up all basics in embedded C by reading this article.
Thanks a lot Amlendra for your effort.
REPLY
Amlendra (https://aticleworld.com/)
REPLY
Saju
MARCH 28, 2019 AT 10:43 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-2476)
REPLY
JAIKRISHNA
MAY 20, 2019 AT 7:50 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-2774)
REPLY
karthik Karthik
MAY 21, 2019 AT 2:52 PM (HTTPS://ATICLEWORLD.COM/EMBEDDED-C-INTERVIEW-QUESTIONS-2/#COMMENT-2779)
THANK YOU………
REPLY
Leave a Reply
Enter your comment here...
(https://www.udemy.com/?ranMID=39197&ranEAID=UajS5soDmWY&ranSiteID=UajS5soDmWY-
ZAN8mpepGLirkhLP5qf9Nw&LSNPUBID=UajS5soDmWY)
Categories
(https://pluralsight.pxf.io/c/1192901/424552/7490?
u=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fwww.pluralsight.com%2Fcourses%2Fc-programming-language-in-action)
Join Aticleworld
You will also get our free C interview questions eBook
Subscribe
Pages
About (https://aticleworld.com/about/)
Guest Article (https://aticleworld.com/guest-article/)
Blog Posts (https://aticleworld.com/blog-post/)
affiliate-disclosure (https://aticleworld.com/affiliate-disclosure/)
disclaimer (https://aticleworld.com/disclaimer/)
Categories
P R O U D LY P O W E R E D B Y W O R D P R E S S ( H T T P S : // W O R D P R E S S . O R G / ) | T H E M E : T H E