C++ Functions, Arrays & Pointers Explained — Beginner's Programming Guide Episode 8 (Updated June 2026) (Updated June 2026)
Here's the thing about C++ — the language doesn't hide memory from you, and that's both its biggest strength and its steepest learning curve. Functions, arrays, and pointers are where most beginners either click with C++ or give up on it. Trust me when I say this: getting comfortable with pointers opens doors that no other language can. Game companies, automotive ECU teams at Bajaj Auto and Tata Tech, and embedded systems engineers throughout Maharashtra's AURIC industrial park (₹71,343 crore investment, 62,405 jobs) write C++ every day precisely because it gives direct memory control. Episode 8 of our C++ Beginner's Guide breaks down these three critical topics into concepts you can actually use.
- Functions in C++ can pass arguments by value (copy) or by reference (direct access) — understanding the difference is critical for performance
- Arrays store multiple values of the same type in contiguous memory locations — the name of an array is a pointer to its first element
- Pointers store memory addresses rather than values — they enable dynamic memory allocation and efficient data structure manipulation
- Pointer arithmetic allows traversal of arrays and dynamic data structures by incrementing/decrementing memory addresses
- new and delete manage heap memory in C++ — forgetting delete causes memory leaks that crash production applications
C++ Functions — Parameters, Return Values, and Scope
A function in C++ is a named block of code that performs a specific task and can be called from anywhere in the program. Every C++ program has at least one function — main() — but real-world programs like the simulation software at Bajaj Auto and Mahindra's engineering teams have thousands. Functions have a return type, a name, an optional parameter list, and a body. The scope of variables declared inside a function is local — they don't exist outside the function's braces. Static local variables are the exception: they retain their value between function calls, which is useful for counting function invocations or caching results.

Pass by Value vs Pass by Reference — When to Use Each
When you pass a variable to a function by value, C++ creates a copy of that variable — changes inside the function don't affect the original. When you pass by reference (using & in the parameter type), the function works directly on the original variable — changes inside the function do affect the original. Pass by reference is critical for performance when working with large objects like matrices or vectors, since copying a 1,000-element array on every function call would be catastrophically slow. The rule of thumb: pass fundamental types by value, pass objects and arrays by reference (or pointer), and use const references when the function shouldn't modify the argument.
| Passing Mode | Syntax | Modifies Original? | Best For |
|---|---|---|---|
| By Value | void f(int x) | No | Small types (int, float) |
| By Reference | void f(int &x) | Yes | Large objects, in/out params |
| By Const Ref | void f(const int &x) | No | Read-only large objects |
| By Pointer | void f(int *x) | Yes (if dereferenced) | Arrays, optional params |
Arrays in C++ — Declaration, Initialisation, and Iteration
An array in C++ is a collection of elements of the same data type stored in contiguous memory locations. You declare an array with its type, name, and size: int scores[10]; creates space for ten integers. What most beginners don't realise is that the array name itself (scores) is actually a pointer to the first element (scores[0]) — this is why arrays and pointers are so tightly coupled in C++. You access elements with the subscript operator: scores[0] is the first element, scores[9] is the last. Accessing outside the bounds (scores[10]) causes undefined behaviour — one of the most common bugs in C++ code at any experience level.

Pointers — What They Are and Why They Matter
A pointer is a variable that stores the memory address of another variable. Declare a pointer with an asterisk: int* p; creates a pointer to an integer. Assign an address using the address-of operator: p = &x; now p holds the memory address of x. Dereference a pointer to access the value it points to: *p gives you the value of x. Pointer arithmetic is what makes C++ powerful for systems programming — incrementing an int pointer by 1 moves it forward by 4 bytes (the size of an int), allowing efficient traversal of arrays and data structures without index arithmetic. Embedded systems teams at Siemens India and Bosch use pointers constantly in register-mapped peripheral control code.
Dynamic Memory with new and delete
C++ has two memory regions: stack (managed automatically, limited in size) and heap (managed manually, much larger). The new keyword allocates memory on the heap: int* arr = new int[100]; creates an array of 100 integers on the heap. The delete keyword releases that memory: delete[] arr; Every new must have a corresponding delete — failing to free heap memory causes memory leaks that accumulate over time and eventually crash production applications. Modern C++ (C++11 and later) provides smart pointers (unique_ptr, shared_ptr) that automatically manage heap memory, but understanding raw pointers is still essential — you'll encounter them in every legacy C++ codebase and in interview questions at companies like KPIT, Infosys BPM, and embedded firms.
Maharashtra's CMYKPY (Chief Minister Yuva Karya Prashikshan Yojana) provides apprenticeship stipends of ₹6,000–₹10,000 per month for students pursuing C++ and embedded software development training. ABC Trainings guides eligible candidates through the application process and connects them with software and engineering companies in Pune, Sambhajinagar, and Kolhapur.Get the IT & Programming Brochure + Fees + Batch Dates on WhatsApp
Free 1:1 counselling. Placement track record. CMYKPY/PMKVY eligibility check.
💬 Get Brochure on WhatsApp📞 Call 7039169629About the author: Rahul Patil. 12 yrs experience training engineers across Maharashtra.
Visit Our Centers
- Wagholi (Pune): 1st Floor, Laxmi Datta Arcade, Pune-Ahilyanagar Highway. Call 7039169629
- Hadapsar (Pune HQ): 1st Floor, Shree Tower, opp. Vaibhav Theater, Magarpatta. Call 7039169629
- Cidco (Chh. Sambhajinagar): Kalpana Plaza, opp. Eiffel Tower, N-1 Cidco. Call 7039169629
- Osmanpura (Chh. Sambhajinagar): S.S.C Board to Peer Bazar Road, near Jama Masjid. Call 7039169629
- Sangli: Shubham Emphoria, 1st Floor, Above US Polo Assn., Sangli-Miraj Rd, Vishrambag. Weekend batches available. Call 7039169629
FAQs
What is the difference between pass by value and pass by reference in C++?
Pass by value creates a copy of the argument — changes inside the function don't affect the original variable. Pass by reference passes the actual memory address — changes inside the function directly modify the original. Use pass by value for small types like int and float; use pass by reference for large objects and arrays to avoid unnecessary copying overhead.
Are arrays and pointers the same thing in C++?
They're closely related but not identical. An array name acts as a pointer to its first element, so array[i] is equivalent to *(array + i). However, a pointer is a variable that can be reassigned to point to different memory locations, while an array name is a constant pointer — you can't make it point somewhere else. Arrays are fixed-size; pointers can point to dynamically allocated memory of any size.
What is a memory leak in C++ and how do I prevent it?
A memory leak occurs when you allocate memory on the heap with new but never release it with delete — the memory remains allocated even after the pointer goes out of scope and the application has no way to free it. Over time, leaked memory accumulates and exhausts available RAM, crashing the program. Prevent leaks by always pairing new with delete, using RAII patterns, and preferring smart pointers (unique_ptr, shared_ptr) in modern C++ code.
Do I still need to learn pointers if I'm using modern C++?
Yes, absolutely. Smart pointers (unique_ptr, shared_ptr) handle memory management automatically, but they use raw pointers internally. You'll encounter raw pointers in every existing C++ codebase, in embedded systems code, in interview questions at KPIT, Tata Tech, and Bajaj Auto engineering teams, and in the C++ standard library itself. Understanding raw pointers also makes you a better smart-pointer user because you know exactly what they're doing under the hood.



