Technical Interview Q&A: C++ vs Go, Thread Communication, Goroutine, TCP Handshake, SQL, and More
This article compiles a series of technical interview questions and answers covering C++ and Go language differences, thread communication methods on Linux and Windows, stack versus heap memory, orphan processes, read‑write locks, Go goroutine concurrency, TCP three‑way handshake, and a sample SQL query for gender‑based grouping.
The article presents a collection of technical interview questions and detailed answers that are useful for candidates preparing for software engineering roles.
2. Differences between C++ and Go
Syntax complexity: C++ has a complex syntax with templates and multiple inheritance, while Go offers a simple, easy‑to‑learn syntax without class inheritance.
Performance: C++ provides near‑hardware performance suitable for high‑performance computing; Go offers sufficient performance with strong support for concurrency and network services.
Memory management: C++ uses manual memory management with new and delete (or smart pointers); Go uses automatic garbage collection.
Concurrency: C++11 introduced threads but concurrency is relatively complex; Go has native support via goroutines and channels.
Compilation speed: C++ compilation is usually slower, especially for large projects; Go compiles quickly.
Error handling: C++ uses exceptions or return codes; Go prefers returning error values.
Cross‑platform support: Both are cross‑platform, but Go provides seamless cross‑compilation.
3. Thread communication methods on Linux and Windows
Linux mechanisms include signals, mutexes, read‑write locks, spin locks, condition variables, and semaphores. Windows mechanisms include volatile global variables, message passing via PostMessage and PostThreadMessage , and synchronization objects such as CEvent .
4. Stack vs. Heap
Stack memory is allocated automatically by the system, has a fixed size (default 4 MiB), and offers fast allocation without fragmentation. Heap memory is manually allocated and freed by the programmer, can grow dynamically (typically 1 GiB–4 GiB), but allocation is slower and may fragment.
5. Orphan processes
If a parent process exits before its child, the child becomes an orphan and is adopted by the init process (PID 1), which then reaps its exit status.
6. Read‑write lock
Multiple readers may hold the lock simultaneously, while writers obtain exclusive access; writers are given priority over readers.
7. Why Goroutine supports high concurrency
Goroutines are lightweight (≈2 KB), use user‑space scheduling, and communicate via channels, resulting in lower context‑switch overhead compared to OS threads.
8. Go defer usage
defer registers a function to run after the surrounding function returns, useful for resource cleanup, lock release, and ensuring actions occur in LIFO order.
9. Slice vs. array in Go
Arrays have fixed length and are value types; slices have dynamic length, are reference types, and provide flexible operations such as append . Example:
package main
import "fmt"
func main() {
// Create a slice
numbers := []int{1, 2, 3, 4, 5}
// Append elements
numbers = append(numbers, 6)
numbers = append(numbers, 7, 8, 9)
// Print slice
fmt.Println(numbers)
}10. TCP three‑way handshake
The client starts in closed state and the server in listen . The handshake proceeds as follows:
Client sends SYN (seq = x) → server receives it.
Server replies with SYN+ACK (seq = y, ack = x+1).
Client sends ACK (seq = x+1, ack = y+1) and the connection enters established state.
11. Sample SQL query
Group students by gender and compute total count and average score:
SELECT sex, COUNT(*) AS total_students, AVG(score) AS average_score
FROM grades
WHERE sex IN ('male', 'female')
GROUP BY sex;The article also contains personal anecdotes about Huawei recruitment, but the core technical content provides valuable knowledge for backend development and system programming.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.