Jan 19, 2026
C/CPP Interview Questions
✅ C & C++ Interview Question Bank (With Answers)
🔹 SECTION 1: C LANGUAGE (Core)
Q1. What is the difference between malloc() and calloc()?
Answer:
malloc calloc
Allocates memory Allocates & initializes to zero
Faster Slightly slower
Takes 1 argument Takes 2 arguments
⸻
Q2. What is a dangling pointer?
Answer:
A pointer that points to a memory location that has been freed or gone out of scope.
⸻
Q3. Difference between const int *p and int *const p?
Answer:
• const int *p → value cannot be changed
• int *const p → pointer cannot be changed
⸻
Q4. What is static keyword used for?
Answer:
• Preserves variable value between function calls
• Limits scope to file when used globally
• Shares value across objects in C++
⸻
Q5. What is volatile keyword?
Answer:
Tells compiler not to optimize variable since it can change externally (used in hardware registers, ISR).
⸻
Q6. What is segmentation fault?
Answer:
Accessing invalid or unauthorized memory location.
⸻
Q7. What is structure padding?
Answer:
Extra bytes added by compiler to align data for faster access.
⸻
Q8. What is difference between stack and heap?
Answer:
Stack Heap
Automatic allocation Manual allocation
Faster Slower
Limited size Larger size
⸻
🔹 SECTION 2: POINTERS (Very Important)
Q9. What is pointer to pointer?
Answer:
A pointer that stores address of another pointer.
⸻
Q10. What is NULL pointer?
Answer:
Pointer that points to nothing (NULL or 0x0).
⸻
Q11. What is function pointer?
Answer:
A pointer that points to a function’s address.
⸻
Q12. Difference between array and pointer?
Answer:
• Array name is constant
• Pointer can be reassigned
⸻
🔹 SECTION 3: C++ BASICS
Q13. What is OOP?
Answer:
Programming model based on Object, Class, Encapsulation, Inheritance, Polymorphism, Abstraction.
⸻
Q14. Difference between C and C++?
Answer:
• C → procedural
• C++ → object oriented
• C++ supports classes, inheritance, STL
⸻
Q15. What is constructor?
Answer:
Special function automatically called when object is created.
⸻
Q16. What is destructor?
Answer:
Function called automatically when object is destroyed.
⸻
Q17. Can constructor be private?
Answer:
Yes (used in Singleton pattern).
⸻
Q18. What is copy constructor?
Answer:
Initializes object using another object of same class.
⸻
Q19. What is virtual function?
Answer:
Function that supports runtime polymorphism using base class pointer.
⸻
Q20. What is virtual destructor?
Answer:
Ensures proper cleanup of derived class object.
⸻
🔹 SECTION 4: OOP CONCEPTS
Q21. What is encapsulation?
Answer:
Binding data and methods together and hiding internal details.
⸻
Q22. What is inheritance?
Answer:
Derived class inherits properties of base class.
⸻
Q23. What is polymorphism?
Answer:
Same function name behaving differently.
⸻
Q24. Difference between compile time and runtime polymorphism?
Answer:
• Compile time → function overloading
• Runtime → function overriding
⸻
Q25. What is abstraction?
Answer:
Showing only essential features, hiding implementation.
⸻
🔹 SECTION 5: ADVANCED C++
Q26. What is STL?
Answer:
Standard Template Library providing containers, algorithms, iterators.
⸻
Q27. Difference between vector and list?
Answer:
vector list
Contiguous memory Non-contiguous
Fast access Slow access
Slow insertion Fast insertion
⸻
Q28. What is smart pointer?
Answer:
Pointer that automatically manages memory.
Examples:
• unique_ptr
• shared_ptr
• weak_ptr
⸻
Q29. What is RAII?
Answer:
Resource Acquisition Is Initialization — resource tied to object lifetime.
⸻
Q30. What is namespace?
Answer:
Used to avoid name conflicts.
⸻
🔹 SECTION 6: EMBEDDED / SYSTEM C & C++
Q31. Why use volatile in embedded systems?
Answer:
Variables can change due to hardware or interrupts.
⸻
Q32. What is ISR?
Answer:
Interrupt Service Routine — function executed on interrupt.
⸻
Q33. What is memory leak?
Answer:
Allocated memory not freed.
⸻
Q34. Difference between new/delete and malloc/free?
Answer:
• new/delete call constructors/destructors
• malloc/free do not
⸻
Q35. What is deadlock?
Answer:
Two processes waiting for each other indefinitely.
⸻
🔹 SECTION 7: COMMON TRICK QUESTIONS
Q36. Can main() be overloaded?
Answer:
No.
⸻
Q37. Can we have virtual constructor?
Answer:
No, but destructor can be virtual.
⸻
Q38. Can sizeof return zero?
Answer:
No.
⸻
Q39. Is C pass by value or reference?
Answer:
C supports only pass by value (reference via pointers).
⸻
Q40. Why sizeof(char) is always 1?
Answer:
Defined by C standard.
⸻
Huffman Decoder
Huffman decoder is used for data compression.
- The Tree Search: In a Huffman tree, we start at the Root.
- The Binary Path:
- If the bit is 0, we move to the Left child.
- If the bit is 1, we move to the Right child.
- The Leaf Node: When we reach a "Leaf" (a node with a letter), we record that letter and jump back to the Root to start the next letter.
- Efficiency: Because no code is a prefix of another (Prefix Property), the decoder always knows exactly when a letter ends.
- Map:
A:0, B:10, C:110, D:111 - Encoded String:
010110111 - Decoding Process:
0→ A10→ B110→ C111→ D
- Result: ABCD
Decoder: Huffman Coding 📟
Jan 7, 2026
UPF : Power Switch
UPF: Power Switch details — Power Switch in UPF (Unified Power Format) is used to control power gating (turning a power domain ON/OFF) to save leakage power in low-power VLSI designs.
A power switch represents a set of header (PMOS) or footer (NMOS) transistors that connect/disconnect a power domain using enable/control signals—allowing blocks to be shut down during idle mode.
Why a Power Switch is needed
- Reduce leakage power
- Enable power-gated domains (power islands)
- Essential for mobile / low-power SoC designs
Where it is used
- VDD → Power-gated domain (header switch)
- Power-gated domain → VSS (footer switch)
Key UPF elements involved
create_power_domaincreate_supply_portcreate_supply_netcreate_power_switchset_domain_supply_net
Simple UPF Power Switch example
create_power_domain PD_CORE
create_supply_port VDD
create_supply_port VSS
create_supply_net VDD
create_supply_net VSS
connect_supply_net VDD -ports VDD
connect_supply_net VSS -ports VSS
create_power_switch PSW_CORE \
-domain PD_CORE \
-input_supply_port {VDD VDD} \
-output_supply_port {VDD_SW VDD} \
-control_port {PS_EN} \
-on_state {ON PS_EN}
Meaning
- PSW_CORE → Power switch name
- VDD → VDD_SW → Switched power
- PS_EN → Enable signal
- When PS_EN = 1 → Power ON
- When PS_EN = 0 → Power OFF
Header vs Footer switch
| Type | Transistor | Position | Common use |
|---|---|---|---|
| Header | PMOS | Between VDD & block | Low noise |
| Footer | NMOS | Between block & GND | Area efficient |
Power switch with isolation & retention (typical flow)
- Power switch OFF
- Isolation enabled
- State retained (if needed)
- Power switch ON
- De-isolation
Real-world SoC usage
- CPU core sleep mode
- GPU power islands
- Peripheral shutdown blocks
Timing-safe power-up sequence (UPF)
Power-Up Order (Recommended)
- Keep Isolation ON (clamp outputs to a known value)
- Enable Power Switch (ramp-up)
- Wait for Power Good (PG)
- Restore Retention Registers
- Release Reset
- Enable Clock
- Disable Isolation
set_isolation ISO_CORE -domain PD_CORE -clamp_value 0
# Enable power switch
# PS_EN = 1
wait (PWR_GOOD == 1);
set_retention_control RET_CORE -restore_signal RET_RESTORE
# Release reset
# RESET_N = 1
# Enable clock
# CLK_EN = 1
set_isolation_control ISO_CORE -isolation_signal ISO_EN -deassert
Isolation ON → Power ON → Power Good → Retention Restore → Reset Release → Clock ON → Isolation OFF
What happens if sequence is wrong?
| Mistake | Result |
|---|---|
| Isolation OFF before power | X-propagation |
| Clock ON before power | Short-circuit current |
| Reset before power good | Unknown state |
| No PG wait | Timing failures |
UPF Interview Questions & Answers
| Isolation | Retention |
|---|---|
| Protects outputs | Preserves internal state |
| Mandatory | Optional |
| Active when power OFF | Active before power OFF |
| Header | Footer |
|---|---|
| PMOS | NMOS |
| Low noise | Area efficient |
| Near VDD | Near GND |
- Power-aware STA
- UPF consistency checks
- PG signal timing validation
- Isolation/retention sequencing verification
Jan 5, 2026
Jan 2, 2026
Low Power Design : Level Shifter
Low-Power Design: Level Shifters
A level shifter is a circuit used in low-power digital design to safely transfer signals between blocks operating at different voltage levels (VDDs). They are critical in multi-voltage (multi-VDD) and power-gated SoC designs.
Why level shifters are needed
- Prevents over-voltage stress that can damage transistors
- Ensures logic '1' is recognized correctly at the receiving voltage
- Reduces leakage current from high-VDD to low-VDD domains
- Prevents back-powering when one domain is power-gated OFF
Typical low-power SoC scenario
| Block | Supply |
|---|---|
| Always-ON (AON) | 1.0 V |
| Logic core | 0.8 V |
| High-performance | 1.2 V |
Signals crossing these domains must use level shifters.
Types of level shifters
- Converts lower voltage logic to higher voltage
- Most common type
- Often uses cross-coupled PMOS structure
- Converts higher voltage logic to lower voltage
- Often simpler (sometimes a buffer is enough, but leakage must be checked)
- Used in buses (I2C, GPIO, open-drain style interfaces)
- Direction can change dynamically
Where level shifters are placed
| Situation | Typical placement |
|---|---|
| Signal enters higher-VDD domain | At receiver side (destination) |
| Signal enters lower-VDD domain | Often at sender side (source) to avoid over-voltage at destination |
| Power-gated block crossings | Depends on UPF policy + isolation strategy |
Low-power design considerations
- Level shifters can leak if always powered
- Use high-Vt cells, power-gated LS (when allowed), or retention-aware solutions
OFF domain -> Isolation -> Level Shifter -> ON domain
Level shifters vs isolation cells
| Feature | Level Shifter | Isolation Cell |
|---|---|---|
| Voltage conversion | Yes | No |
| Blocks leakage/back-powering | Not guaranteed | Yes |
| Prevents X propagation from OFF domain | No | Yes |
| Used across power domains | Yes | Yes |
UPF example (intent)
create_power_domain PD_HIGH
set_level_shifter LS_L2H \
-from PD_LOW \
-to PD_HIGH \
-location to
With UPF, EDA tools can automatically insert the correct level shifter type and handle placement/connectivity based on your rules.
Common interview questions on level shifters
A: They drive signals at higher VDD and add extra capacitance (higher switching energy).
Q: Can isolation replace level shifters?
A: No. Isolation does not change voltage levels; it clamps values when a domain is OFF.
Q: What happens if a level shifter is placed in a switched-off domain?
A: Output collapses or becomes invalid, causing functional failures.
More interview + concept-checking questions (Basic to Advanced)
Below are additional questions grouped by topic for interview preparation.
- What is a level shifter and why is it required in low-power design?
- Can a buffer replace a level shifter? When and why?
- What happens if a low-VDD output directly drives a high-VDD input?
- Difference between L2H and H2L level shifters?
- Are level shifters combinational or sequential?
- Can level shifters introduce delay? Why?
- Where to place a level shifter: source or destination domain? Why?
- Why are some level shifters placed in Always-ON (AON) domain?
- Can level shifters be power-gated?
- What is back-powering, and how do you prevent it?
- Do all signals crossing domains need level shifters?
- Difference between level shifter and isolation cell?
- Why is isolation often needed along with level shifters?
- For OFF -> ON crossings: Isolation then Level Shifter or Level Shifter then Isolation? Explain.
- How are level shifters treated in STA?
- Can level shifters cause hold violations? Why?
- Do designers instantiate level shifters in RTL, or are they inserted by tools?
- Explain UPF command: set_level_shifter -from PD1 -to PD2 -location to
- Chip works at typical corner but fails at low voltage - what level shifter issues could cause this?
- Simulation clean but silicon fails - what LS problems to suspect?
- X-propagation seen after power-up - LS or isolation issue?
Glitch Free clock gating cells in digital design
This is one of the basic question asked in digital design interviews. Glitch on clock is very dangerous .
Glitch-Free Clock Gating Cells in Digital Design
Clock gating is used to reduce dynamic power by stopping the clock to parts of a circuit when they are not active. A glitch-free clock gating cell (CGC) ensures that the gated clock does not produce spurious pulses (glitches) that could cause incorrect behavior in sequential logic.
⸻
Why glitches happen in naive clock gating
If you simply gate a clock using an AND/OR gate:
gated_clk = clk & enable
Problems:
• enable may change while clk is HIGH
• This can create short pulses or missing edges
• Flip-flops may capture incorrect data or go metastable
⸻
Key idea of glitch-free clock gating
👉 Latch the enable signal only when the clock is in its inactive phase
Then use the latched enable to gate the clock.
⸻
Standard glitch-free clock gating structure
For positive-edge triggered flip-flops
Components:
1. Level-sensitive latch (transparent when clk = 0)
2. AND gate
enable
|
v
+-----------+
| LATCH | (transparent when clk = 0)
+-----------+
|
v
clk -----> AND ----------------> gated_clk
Operation:
• When clk = 0:
enable can safely change → latch updates
• When clk = 1:
latch holds its value → no glitch
• AND gate ensures clock passes only when latched enable = 1
⸻
RTL example (synthesizable, CGC-friendly)
module clock_gating (
input wire clk,
input wire enable,
output wire gated_clk
);
reg enable_latched;
always @(clk or enable) begin
if (!clk)
enable_latched <= enable;
end
assign gated_clk = clk & enable_latched;
endmodule
⚠️ Note:
This style is recognized by synthesis tools and mapped to a standard clock gating cell from the library.
⸻
Integrated Clock Gating (ICG) Cells
In real ASIC flows, designers do not code gates manually.
Libraries provide ICG cells with:
• Built-in latch
• AND/OR logic
• Test enable (scan_enable)
• Low skew and low insertion delay
Typical ICG ports:
• CLK – input clock
• EN – functional enable
• SE – scan enable (forces clock ON during test)
• GCLK – gated clock output
⸻
With scan/test support
effective_enable = EN | SE
This ensures clocks are not blocked during:
• Scan shift
• ATPG
• DFT testing
⸻
Best practices
✅ Use library-provided ICG cells
✅ Place CGCs close to clock source
✅ Avoid gating clocks with combinational logic
✅ Ensure enable is synchronous to clock domain
✅ Use clock gating checks in STA tools
❌ Never gate clocks manually with AND/OR gates in final RTL
⸻
FPGA vs ASIC note
• ASIC: Clock gating is common and recommended
• FPGA: Avoid clock gating; use clock enable (CE) instead
⸻
Summary
Aspect Glitch-Free Clock Gating
Glitch risk Eliminated
Power saving High
Uses latch Yes
ASIC friendly Yes
DFT support Yes
Jan 1, 2026
class 8 CBSE science revision test paper free download A4
Here is the link to download the class 8 science CBSE pattern revision test paper.

Did you enjoy this Quiz?
Tell us your score in the Comments! ✍️