Posts

Showing posts from September, 2025

memory alignment

  Q: so when we declare a variable, can it be given an unaligned address, that we have to later fix like this? Great question 👌 — let’s break it down carefully. 🔹 In  normal C code (user-space, standard malloc/stack/global variables): The  compiler and runtime  guarantee that variables are allocated with the correct alignment. Example: int x; // always aligned to 4 bytes on a 32-bit or 64-bit system double y; // usually aligned to 8 bytes You don’t need to “fix” alignment yourself. If the compiler needs padding (inside structs, arrays, etc.), it will add it automatically. So in everyday application code, you’ll  never see an  int  at an odd address  unless you deliberately break the rules. 🔹 Where unaligned addresses  can  happen: Packed data (files, network packets, protocols): struct __ attribute__ (( packed )) Header { char a; int b; // may be at offset 1, unaligned }; If you directly read  hdr->b , tha...

interview questions

Given parent node and child nodes, Construct the tree by linking all the nodes  medium-level graph questions Graph Traversal (BFS / DFS) Number of Islands (LeetCode 200) Count connected components in a grid (BFS/DFS/Union-Find). Rotting Oranges (LeetCode 994) Multi-source BFS. Detect Cycle in Undirected Graph Using BFS/DFS + parent tracking. Detect Cycle in Directed Graph Using DFS recursion stack or Kahn’s Algorithm (topological sort). Align a given memory address to 4. What do you know about NVIDIA? Why is NVIDIA excelling in AI? Name a few products by NVIDIA. 1 programming problem everyday. 1 topic, either from office (ufs, virtio, hypervisor) or self topics to revise. do programming after 10:30pm to 1:00 am