0% found this document useful (0 votes)
13 views9 pages

Embedded C

Uploaded by

Akshaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

Embedded C

Uploaded by

Akshaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Size of int : 4, float:4,char:1,double:8


2. Size of pointer : It is consistent for all datatypes. It is a holder to hold
address. It will vary with architecture. 4 bytes is the size of 32 bit
microcontroller, 8bytes is the size of 64 bit microcontroller.
3. NULL POINTER: Pointer that points nowhere. It is always
recommended to define the pointer with NULL else it can store garbage
values.
Eg: #include<stdio.h>
int *p;
p= NULL;
Printf(“the value of p is %u”,p); // value is 0.
4. Void pointer: Special type of pointer.It can refer to any datatype like
int,float,char. Instead of creating 3 different pointers I can have 1 void
pointer and use it for any datatype by typecasting.
Eg: #include<stdio.h>
Int I = 3;
Float f = 4.5;
Void *vp;
Vp =&I;
Printf(“Value of I is %d”,((int*)vp));//3
Printf(“Value of f is %f”,((float*)vp));//4.5

5. ISR : Interrupt Service Routine. Its an interrupt handler means


whenever I get any interrupt I need to call that particular subroutine to
execute the interrupt. This subroutine is called ISR. ISR doesn’t return
anything.

6. Interrupt Latency : Latency means delay. The time that ISR takes to
respond to an interrupt is called interrupt latency. It can be reduced by
writing small and efficient code. Don’t write more loops in ISR. Don’t
disable interrupts as it has more latency.

7. Volatile Keyword: when a variable is declared as volatile it informs the


compiler not to optimise the variable.The value of the variable can be
changed anytime outside the scope of the prgm as well. Volatile
keyword is used when we work with registers, when we declare a
variable as global where it can be shared by mutiple threads/tasks.

8. Const vs Variable: when variable declared as const the compiler


ensures that the value of the variable can’t be changed. If changed it
shows error. When variable declared as volatile,we don’t want the
compiler to optimise the variable. We can use pointer as volatile
variable.

9. Nested Interrupt: We get multiple interrupt request and we handle


them based on highest priority, but all interrupts will be handled.

10. Inline function : By default supported in C++, when declared as inline


the whole function body is replaced by function call. Time to execute the
fn gets reduced as it doesn’t want to search where the fn is called,
defined etc. But code size will be increased.

11. Static : Can be used for both variable and function. If declared as
static it is used to preserve the value of the variable throughout the
lifetime of the program. It is initialised once and can’t be reinitialised.It is
explicitly initialised as 0 by the compiler.We can’t create static variable
inside a function.

Memory map of C:
Text ---> A text segment, also known as a code segment or simply as
text, is one of the sections of a program in an object file or in memory,
which contains executable instructions.

Initialized data: static int I =10, global int j= 10


Uninitialized data: static int I , global int j
Stack : LIFO method, Stack pointer is used to identify the top of the
stack.When a function is called all the details abt the function(where it
shd return, what values it shd store) everything is kept as stack frame. If
it is a recursive fn, a new stack frame is created everytime when the fn is
called.

Heap: used to store global data (we use calloc,malloc,free)

12. Semaphore: It is one of the IPC (Inter Process Communication)


mechanism which controls access to the resource. Binary semaphore
controls with 0/1. Counting semaphore can count large values. Railway
track and train example.

13. ## - Token pasting/ Concatenation operator. Used to take 2


arguments together,
#define a(x,y) x##y
printf(“%s”,a(sachin,tendulkar)); //o/p: sachintendulkar.

14. Int* const myptr = &x; ( type Int, constant pointer to an int)
15. Const int *myptr = &x ( Regular pointer to constant int)
16. Const int const *ptr = &x : constant int to const ptr , x can be
changed but pointer can’t be changed.

BIT MANIPULATION OPERATORS RECAP

1. To check if num is odd/even: num&1 if it returns 1 its odd else its


even

2. To check if the particular bit is set/not in a given number:


Step 1: Left shift by the requested bit to check (1<< bit to check)
Step 2: Do bitwise AND, if result is 1 bit is set else its not
Eg: num = 84 to check if 4th bit is set/not
84 = 1010100
1<< 4= 10000
84 & (1<<4): 1 ( so 4th bit is set)

3. To set particular bit in number if not already set:


num |(1<<requested bit)

4. To unset the particular bit if it is already set


Num& ~(1<<requested bit)
~(1<<requested bit) will only negate that particular bit, after which if
we perform AND operation it is 0.

For a C programming interview, it's crucial to have a strong understanding of various data types. Here's a brief
overview:

Subscribe my channel for more.


https://lnkd.in/dGdNRGkU

1. Basic Data Types:


- `int`: Typically 32 bits, but can vary based on the system (16-bit, 32-bit, or 64-bit).
- `char`: Typically 8 bits.
- `float`: Typically 32 bits (single-precision floating-point).
- `double`: Typically 64 bits (double-precision floating-point).

2. Derived Data Types:


- `Arrays`: Size depends on the number of elements and the size of each element.
- `Pointers`: Typically 32 or 64 bits depending on the system (32-bit or 64-bit).
- `Structures`: Size depends on the size of its members and padding added by the compiler.
- `Unions`: Size is the size of the largest member.

3. Modifiers:
- `signed` and `unsigned`: Typically 32 bits for `int` on most systems.
- `short`: Typically 16 bits.
- `long`: Typically 32 bits on a 32-bit system and 64 bits on a 64-bit system.

4. Type Qualifiers:
- `const` and `volatile` do not affect the size of the data types.

5. Enumerated Data Types:


- Size depends on the number of elements in the enumeration.

6. Void Data Type:


- No size, as it represents the absence of type.

In an interview, you might be asked about:


- How the size of data types can vary based on the system architecture.
- The impact of data type sizes on memory usage and program performance.
- How to determine the size of a data type on a specific system.
- How to handle data types of different sizes in a portable and efficient way.

Understanding the sizes of different data types is important for writing efficient and portable code.

1. Storage Classes (Important & Easy)


2. Pointers (Important & Tough)
3. Bitwise Operators (Important & Tough)
4. Structure & Unions (Important & Easy)
5. Strings (Moderate & Easy)
6. Arrays (Important & Easy)
7. Function Pointers (Important & Tough)
8. Files (Moderate & Easy)
9. Data Structures (Moderate & Tough)
10. Macros or Preprocessors (Important & Easy)
11. Dynamic Memory Allocations (Important & Easy)

C Language : Operators in C, arrays, Pointers in complete depth, Dynamic Memory Allocation, Structures
and Unions, file handling, recursion, using data structures like stack, queue, Linked Lists, Tree, Graphs.
Basic Algorithms: merging and sorting
C++ Language : Objects and Classes, OOPS Concepts like Inheritance, Polymorphism, encapsulation,
abstraction and data hiding, OOPS templates, overloading, inlining, C++ STL (Standard Template
Libraries)
Embedded C : Using Bitwise operators, concept of super loop, interrupts, watchdog timers, Software
Architectures like Round Robin, Round Robin with Interrupts, Function Queue Scheduling and RTOS
(Real Time Operating System), writing sub routines, communicating over UART, working with serial
protocols like I2C, SPI and CAN, input/output device coding and interfacing like an Keypad/LCD, basic
assembly language programming.
Operating System : Any real time operating Systems like Free RTOS, Rtx51 tiny or Rtx51, micro-controller
OS-2 (uC OS-2), hands on Linux OS any distribution, basic idea of working of proprietary RTOS like
Vxworks, basic idea of Kernel, semaphores, mailboxes and mutex, Networking concepts.
Microprocessor/Microcontroller : RISC vs CISC, Harvard Vs Von Neumann Vs Modified Harvard
Architecture, 32 bit vs 64 bit processors, Registers, Arithmetic and Logical unit, Timers and Counters,
ADC/DAC’s, basics of 8 bit/ 16 bit architectures, any instruction set, basics of ARM Architecture.

Compute XOR from 1 to N using bitwise operators


int computeXOR(int n)
{
if (n % 4 == 0)
return n;
if (n % 4 == 1)
return 1;
if (n % 4 == 2)
return n + 1;
else
return 0;
}

Array Programs
1. Largest Element in Array
int main()
{
int a[5]= {1,2,50,150,40};
int max = a[0];
for(int i =0;i<5;i++)
{
if(a[i]> max)
{
max = a[i];
}
}
printf("Max element in array%d",max);

return 0;
}

2. Smallest Element in Array


int main()
{
int a[5]= {1,2,50,150,40};
int min = a[0];
for(int i =0;i<5;i++)
{
if(a[i]< min)
{
min = a[i];
}
}
printf("Min element in array%d",min);

return 0;
}
3. Search an element in array
int main()
{
int a[5]= {1,2,50,250,40};
int search_element = 250, flag = 0;
for(int i=0;i<5;i++)
{
if(a[i] == search_element)
{
flag = 1;
}
}
if(flag == 1)
{
printf("Element found");
}
else
{
printf("Element not found");
}

return 0;
}

4. Unique elements in array

int main()
{
int arr[9]= {1,2,2,3,4,4,4,5,5};
int unique_arr[9] = {0};
int count = 0;
int size = sizeof(arr)/sizeof(arr[0]);
for(int i =0;i<size;i++)
{
if(arr[i]!= arr[i+1])
{
unique_arr[i] = arr[i];
printf("Unique elements in array %d\n",unique_arr[i]);
count++;
}
}

printf("Unique elements count %d",count);


return 0;
}
What do you understand by startup code?
 Functions of Startup file?
 What are the differences between process and thread?
 What is ISR?
 Role of Interrupt Vector Table in Interrupt Processing?
 Explain What Is Interrupt Latency? How Can We Reduce It?
 What are the uses of the Keyword Static?
 What does “const int x;” mean?
 Where are constant variables stored in memory?
 How can you protect a character pointer by some accidental modification with the pointer address?
 Can a variable be volatile and const both?
 What is a Null pointer?
 What is the size of a pointer?
 When does a segmentation fault occur?
 What Is Difference Between Using A Macro And Inline Function?
 How can you use a variable in a source file defined in another source file?
 Little and Big Endian Mystery
 List the 4 levels of testing in Embedded Systems.
 What is multithreading and multiprocessing?
 What is Mutex?
 What is Semaphore?
 What are the 2 types of Semaphore?
 Is there any difference between Deadlock and Starvation?
 Difference between RS232 and RS485 (RS232 vs RS485)?
 What is CAN?
 Why CAN?
 Standard CAN vs Extended CAN
 How do CAN bus modules communicate?
 Why Can Is Having 120 Ohms At Each End?
 #define vs const

Volatile : The volatile keyword in C is especially significant in embedded systems


due to the unique nature of hardware interactions and real-time constraints. Here are
some key points highlighting its importance:
Prevents Optimization of Hardware-Dependent Variables
In embedded systems, variables often correspond to hardware registers or memory
locations that can change independently of the program flow (e.g., due to hardware
interrupts, DMA operations, or other peripheral activities). The volatile keyword
tells the compiler that the value of the variable can change at any time, preventing the
compiler from applying certain optimizations that assume the value doesn't change
unexpectedly.
Used with interrupts, Hardware registers(Timers),Memory mapped I/O(UART),

Not to include in ISR: Blocking code, compute computing fns, printf stmts, nested
interrupts because it will increase the latency of the system.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy