Cracking Baidu's C++/PHP Interview: Key Questions, Answers, and QuickSort Code
This article examines the diminishing premium of overseas degrees, suggests one‑year master programs for career advancement, and then provides a comprehensive Baidu interview guide covering C++/PHP fundamentals, memory allocation, networking protocols, process vs thread, Redis performance, and a complete quicksort implementation in C++.
On a professional networking site I saw a "overseas graduate salary table" that made me realize the hype around international education is fading.
For many years parents have spent hundreds of thousands to send their children to international schools abroad, believing it guarantees a well‑rounded, global perspective and an elite job back home.
"The child will acquire a so‑called 'comprehensive development and global vision', then return to China and find a respectable elite position."
Recent experiences of the first batch of returnees earning only ¥8,000 a month have shattered that belief.
Is a foreign degree no longer worth it? For those stuck with a bachelor's degree, a one‑year master’s program can be a cost‑effective way to re‑enter campus recruitment, though it has drawbacks such as limited recognition by some large domestic firms and the financial strain of taking a year off work.
Overall, Chinese tech giants are rapidly de‑mythologizing the "overseas halo"; a foreign degree alone no longer guarantees a high‑salary job.
Baidu First Interview
1. Self‑Introduction + Project Questions
balabalba
2. Difference between new and malloc ?
new/delete are C++ keywords supported by the compiler; malloc/free are library functions requiring header files. new infers the size from the type, while malloc needs an explicit size. new returns a pointer of the exact object type, eliminating the need for casts; malloc returns void* which must be cast.
On failure, new throws std::bad_alloc, whereas malloc returns NULL.
3. Memory Model Overview
The memory model consists of stack, heap, free store, global/static area, constant area, and code area.
Stack : Stores local variables of a function; automatically released when the function returns.
Heap : Memory allocated with new; must be released with delete by the programmer.
Free Store : Abstract concept of dynamically allocated memory in C++ (similar to heap but not identical).
Global/Static Area : Holds global and static variables; uninitialized variables are zero‑initialized.
Constant Area : Stores immutable constants.
Code Area : Contains the binary code of functions.
4. Network Layer Protocols (Five‑Layer Model)
5. What is TTL?
TTL (Time‑to‑Live) is decremented by one at each router; when it reaches zero the packet is discarded and an ICMP "time exceeded" message is sent.
7. How Does TCP Ensure Reliable Transmission?
Acknowledgment and Retransmission : Receiver acknowledges packets; sender retransmits if no ACK is received.
Checksum : Validates packet integrity.
Segmentation and Reordering : TCP fragments data according to MTU and reassembles out‑of‑order packets.
Flow Control : Sliding window prevents receiver overload.
Congestion Control : Adjusts sending rate based on network congestion.
8. Process vs. Thread Differences
Threads start faster and are lightweight.
Processes have higher system overhead.
Threads share heap, global/static variables, pointers, and files; each has its own stack.
9. Is Allocating a Large Memory Block as Efficient as a Small One?
Allocating large blocks usually takes more time because the allocator must search for a sufficiently large contiguous region, may trigger fragmentation‑defragmentation, and often requires a system call ( brk, sbrk, or mmap) to obtain memory from the kernel.
Small allocations are fast: the allocator keeps free‑list bins of common sizes and can satisfy requests without kernel interaction.
10. Why Is Single‑Threaded Redis So Fast?
Most operations run entirely in memory using efficient data structures.
Single‑threaded design avoids lock contention and context‑switch overhead.
Uses I/O multiplexing (select/epoll) to handle many client sockets concurrently.
11. Hand‑Written QuickSort in C++
#include <iostream>
#include <vector>
using namespace std;
// Partition function, using the last element as pivot
int partition(vector<int>& arr, int low, int high) {
int pivot = arr[high]; // choose last element as pivot
int i = low - 1; // boundary of elements less than pivot
for (int j = low; j < high; j++) {
if (arr[j] <= pivot) {
i++;
swap(arr[i], arr[j]);
}
}
swap(arr[i + 1], arr[high]);
return i + 1;
}
// Recursive quicksort function
void quickSort(vector<int>& arr, int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
// Wrapper for convenience
void quickSort(vector<int>& arr) {
quickSort(arr, 0, arr.size() - 1);
}
int main() {
vector<int> arr = {10, 7, 8, 9, 1, 5};
cout << "Original array: ";
for (int num : arr) cout << num << " ";
cout << endl;
quickSort(arr);
cout << "Sorted array: ";
for (int num : arr) cout << num << " ";
cout << endl;
return 0;
}12. Chat: "Graduated? When can you join?"
Honestly, yes.
13. Reverse Question: Department Introduction and Personal Improvement
My fundamentals are solid; I could later explore source code to deepen my understanding.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
