Jan 19, 2026

C/C++ MCQ - Check your skill set

C / C++ MCQ Quiz

C / C++ Interview MCQ Test

1. Which keyword prevents a variable from being modified?
2. Which operator is used to allocate memory dynamically in C++?
3. Which feature supports runtime polymorphism?
4. What is sizeof(char)?
5. Which container allows fast random access?
6. What is a dangling pointer?
7. Which function frees memory allocated by malloc?
8. Which keyword is used to inherit a class?
9. Which is NOT a C++ access specifier?
10. What does STL stand for?
11. Which loop executes at least once?
12. Which pointer manages memory automatically?
13. What is RAII?
14. Which keyword avoids compiler optimization?
15. What is the output of sizeof(int)?

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.

How the Decoder Works (Educational Steps)
  1. The Tree Search: In a Huffman tree, we start at the Root.
  2. 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.
  3. 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.
  4. Efficiency: Because no code is a prefix of another (Prefix Property), the decoder always knows exactly when a letter ends. 
Example for your Blog Post:
  • Map: A:0, B:10, C:110, D:111
  • Encoded String: 010110111
  • Decoding Process:
    • 0 → A
    • 10 → B
    • 110 → C
    • 111 → D
  • Result: ABCD

Decoder: Huffman Coding 📟

Jan 7, 2026

UPF : Power Switch

UPF: Power Switch Details

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.

UPF • LOW POWER
What is a Power Switch?
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_domain
  • create_supply_port
  • create_supply_net
  • create_power_switch
  • set_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)

  1. Power switch OFF
  2. Isolation enabled
  3. State retained (if needed)
  4. Power switch ON
  5. De-isolation

Real-world SoC usage

  • CPU core sleep mode
  • GPU power islands
  • Peripheral shutdown blocks

Timing-safe power-up sequence (UPF)

This sequence avoids X-propagation, crowbar current, and timing violations during wake-up.

Power-Up Order (Recommended)
  1. Keep Isolation ON (clamp outputs to a known value)
  2. Enable Power Switch (ramp-up)
  3. Wait for Power Good (PG)
  4. Restore Retention Registers
  5. Release Reset
  6. Enable Clock
  7. 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
Golden Rule (Interview Favorite):
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

Q1. What is a power switch in UPF?
Ans: A power switch models header/footer transistors used to connect or disconnect power to a domain for leakage reduction.
Q2. Why is isolation required during power-up?
Ans: To prevent unknown (X) values from propagating from powered-off domains into active logic.
Q3. What is Power-Good (PG) signal?
Ans: A signal indicating that the supply voltage has reached a stable, safe operating level.
Q4. Difference between isolation and retention?
IsolationRetention
Protects outputsPreserves internal state
MandatoryOptional
Active when power OFFActive before power OFF
Q5. Why clocks are enabled last?
Ans: To prevent spurious switching and timing violations during unstable power.
Q6. What is inrush current and how do you avoid it?
Ans: Sudden current surge during power-up; avoided using staggered power switches or ramp-controlled enable.
Q7. Header vs Footer power switch?
HeaderFooter
PMOSNMOS
Low noiseArea efficient
Near VDDNear GND
Q8. What happens if isolation is forgotten in UPF?
Ans: Functional simulation may pass, but gate-level simulation shows X-propagation and silicon failure.
Q9. Can a power-gated domain be clocked?
Ans: No. Clock must be gated OFF before power OFF and enabled only after power-up stabilization.
Q10. What checks ensure timing-safe power-up?
Ans:
  • Power-aware STA
  • UPF consistency checks
  • PG signal timing validation
  • Isolation/retention sequencing verification
“A timing-safe power-up ensures isolation first, stable power next, state restore, then clocks—never the other way around.”

UPF Quiz : On Power Switch

UPF • Power-Up Sequence

UPF Power-Up & Power Switch Quiz

Jan 5, 2026

QUIZ - On UPF - 5 (level Shifter)

⚡ Level Shifter Quiz

Time Left: 300 sec

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.

Key idea: Whenever a signal crosses from one voltage domain to another, it must be protected to avoid reliability issues, incorrect logic levels, leakage, and back-powering.

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

1) Low-to-High (Up-shifter)
  • Converts lower voltage logic to higher voltage
  • Most common type
  • Often uses cross-coupled PMOS structure
Example: 0.8 V -> 1.2 V
2) High-to-Low (Down-shifter)
  • Converts higher voltage logic to lower voltage
  • Often simpler (sometimes a buffer is enough, but leakage must be checked)
Example: 1.2 V -> 0.8 V
3) Bidirectional level shifter
  • 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

1) Leakage power
  • Level shifters can leak if always powered
  • Use high-Vt cells, power-gated LS (when allowed), or retention-aware solutions
2) Dynamic power
Dynamic power is proportional to C x V^2 x f. Up-shifters increase switching energy because they drive at higher VDD and add capacitance.
Tip: minimize number of crossings.
3) Interaction with power gating
If signals come from an OFF domain, they can float or become X. Usually you need isolation before level shifting:
OFF domain -> Isolation -> Level Shifter -> ON domain
If signals go into an OFF domain, the level shifter must remain powered (typically in AON) or the output may collapse.
4) Always-ON requirement
Wake-up, reset, and handshake signals often require LS placed in the AON 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
Important: In real low-power SoCs, both isolation and level shifting are often required together.

UPF example (intent)

create_power_domain PD_LOW
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

Q: Why are level shifters power-hungry?
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.

Basic concepts
  1. What is a level shifter and why is it required in low-power design?
  2. Can a buffer replace a level shifter? When and why?
  3. What happens if a low-VDD output directly drives a high-VDD input?
  4. Difference between L2H and H2L level shifters?
  5. Are level shifters combinational or sequential?
  6. Can level shifters introduce delay? Why?
Placement and power domains
  1. Where to place a level shifter: source or destination domain? Why?
  2. Why are some level shifters placed in Always-ON (AON) domain?
  3. Can level shifters be power-gated?
  4. What is back-powering, and how do you prevent it?
  5. Do all signals crossing domains need level shifters?
Level shifter vs isolation
  1. Difference between level shifter and isolation cell?
  2. Why is isolation often needed along with level shifters?
  3. For OFF -> ON crossings: Isolation then Level Shifter or Level Shifter then Isolation? Explain.
Timing, STA, and UPF
  1. How are level shifters treated in STA?
  2. Can level shifters cause hold violations? Why?
  3. Do designers instantiate level shifters in RTL, or are they inserted by tools?
  4. Explain UPF command: set_level_shifter -from PD1 -to PD2 -location to
Debug scenarios
  1. Chip works at typical corner but fails at low voltage - what level shifter issues could cause this?
  2. Simulation clean but silicon fails - what LS problems to suspect?
  3. 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

SiteMap