C programming skills ChatGPT Flashcards
(56 cards)
What is the difference between ++i
and i++
in C?
++i
increments i
before its value is used. i++
increments i
after its value is used.
What is a pointer in C?
A pointer is a variable that stores the memory address of another variable.
What is a segmentation fault?
A segmentation fault occurs when a program tries to access memory it shouldn’t, like dereferencing a null or invalid pointer.
What is the use of volatile
keyword?
volatile
tells the compiler not to optimize the variable, as it may change unexpectedly (e.g., by hardware).
What are the storage classes in C?
auto
, register
, static
, and extern
.
What are the main differences between a microcontroller and a microprocessor?
Microcontrollers have built-in memory and peripherals; microprocessors require external components.
What is the purpose of const
keyword in embedded C?
const
defines a variable whose value cannot be changed after initialization, useful for read-only memory mapping.
What is the difference between volatile
and const
?
const
prevents modification, while volatile
tells the compiler not to optimize because the value can change externally.
What is the size of int
, short
, long
and long long
in C?
Typically: short
= 2 bytes, int
= 4 bytes, long
= 4 bytes, long long
= 8 bytes (but may vary by system).
How do you declare an interrupt service routine (ISR) in C?
Use the appropriate compiler-specific keyword or attribute (e.g., \_\_attribute\_\_((interrupt))
or ISR(vector)
).
What is a memory-mapped I/O?
Memory-mapped I/O uses specific memory addresses to interact with hardware registers.
What is the use of bit fields in C?
Bit fields allow the packing of data in a struct to use less memory, useful for hardware register definitions. E.g:
struct StatusRegister {
unsigned int ready : 1;
unsigned int error : 1;
unsigned int code : 4;
};
for:
Memory-efficient storage
Representing hardware registers or flags
What is a watchdog timer?
A hardware timer that resets the system if the software fails to periodically reset it.
What are static
variables in C?
static
variables retain their value between function calls and have internal linkage when used at file scope.
What is the difference between malloc
and calloc
?
malloc
allocates uninitialized memory, calloc
allocates and zeroes the memory.
Why is dynamic memory allocation discouraged in embedded systems?
It may cause fragmentation, unpredictable allocation times, and memory leaks.
What is endianess?
The order in which bytes are stored for multi-byte data types: Little Endian (LSB first), Big Endian (MSB first).
What are the different types of timers in microcontrollers?
Basic timers, general-purpose timers, and advanced-control timers (varies by architecture).
What is polling vs. interrupt?
Polling continuously checks for an event; interrupts respond asynchronously when an event occurs.
What is a circular buffer?
A circular buffer is a fixed-size buffer that wraps around to the beginning when the end is reached, ideal for streaming data.
What is a race condition?
A race condition occurs when two threads or ISRs access shared data concurrently and the outcome depends on timing.
What is reentrant code?
Code that can be safely interrupted and re-entered before the previous execution is complete.
What are the types of memory in an embedded system?
ROM, RAM, Flash, EEPROM, and external memory depending on architecture.
What is the use of assert()
in embedded C?
assert()
is used to catch programming errors by verifying assumptions at runtime, typically during development.