Logo

dev-resources.site

for different kinds of informations.

Pointers in C Programming - Lay Man's Analogy

Published at
1/8/2025
Categories
c
softwaredevelopment
backenddevelopment
python
Author
ogagacodes
Author
10 person written this
ogagacodes
open
Pointers in C Programming - Lay Man's Analogy

Jargons

Image description
In the realms of technical jargons here is the definition of pointers in C programming language;

In computer science, a pointer is an object in many programming languages that stores a memory address

I actually copied and pasted that(lol) from here

The problem with the above definition is, even seasoned programmers find it hard to understand and they get lost, sometimes. Here is the thing, I will make a bet, if by the end of this article you don't understand pointers then i owe you, what I will tell at the end. When i say "you" here I mean mostly programmers, begginers or advanced.

A HOUSE AND ADDRESS
Every house has an address, every house has a description - say color, the architectural pattern(the way its built) and sometimes the type. The thing is even an empty land in a street has an address reserved for it(99.9 percent of the time).
Now Picture this scenario, John Doe asks for the descrtiotion of your house, you can either give him the address(A much better and definite way) or a description. One problem of giving him a description is , there is a near to certainty chance that another house might look same as your house or John Doe could easily get confused while looking for the house. But with the address he cannot miss it, he scribbles the house address on paper and takes a look when searching. Keep this near to kindergaten story in mind. Yes, you are right, a house , an address, and empty land space

THE ANALOGY
The street is C, the house is called the value of a space(take the space as say a variable - like a container), the address is stored in the pointer. There can be no same pointer for a value, yes just as there can be no same address for two houses(worst case one will be No 7a, while the other No7b, never same). If you scribble the samne address in two differntb papers, its kind of wasteful , don't you think?? In programming we try to prevent waste, hence one pointer for one address.
However, there can be same type of houses in a street, yes there can same type of values having different pointers and different addreses, in other words, each variable gets a unique memory address unless explicitly made to reference the same address(a small but manageable twist).
Also just as using pointers in C is more optimised so also if you remember, giving your exact address John Doe is much better than describing the house(especially if there are many houses in your street). This is one of many reasosn, I dare argue the core reason why C is a very quick and Efficient programming lanaguage. Linus Benedict Torvalds, the designer of the Linux os, once said

I have never seen a language that is as efficient as C to work with operating systems or machines

APOLOGIES, SOME JARGON
In c here is how it is written as shown in the image below;
Image description

  • *ptr here is a pointer
  • &var here is the address
  • So *ptr is like the paper containing the exact address(&var is the address in memory)
  • The **ptr is a pointer pointing to a pointer, take it as say you need to keep the paper containing the address somewhere, you need to know exactly where that paper is, so it now has its own location or address.
  • The int here is just a neccessary part for completion it just means we are dealing with numbers(integers)

While this is an over simplified analogy, even seasoned programmers will k now this is a start. I sincerly hope this clarifies some misunderstanding.
Funfact: C programming language is one of the backbones of NASA’s flight software

backenddevelopment Article's
30 articles in total
Favicon
How Does This Jewelry Customization Site Work? Need Insights!
Favicon
Building a Secure Authentication API with TypeScript, Node.js, and MongoDB
Favicon
Inter-process Communication with WitCom
Favicon
🚀 Roadmap to Becoming a Full-Stack Web Developer in 2025 🌐
Favicon
JAVA PARA INICIANTES - Orientações gerais e Configurações do Ambiente
Favicon
JAVA PARA INICIANTES - 1. Introdução, Fundamentos e Prática 11/01/25 #Cap1
Favicon
Introduction to Django Authentication: Understanding the Core Components and Benefits
Favicon
WitCom: Modernizing Client-Server Communication
Favicon
POST ABOUT THE TRENDS IN WEB DEVELOPMENT
Favicon
Connecting frontend And Backend In react.js
Favicon
Mastering Image Uploads in Node.js: A Beginner-to-Advanced Guide with Multer and Cloudinary
Favicon
Backend Development Course Structure
Favicon
Introduction to Spring Boot: A Complete Guide
Favicon
Navigating Backend Responsibilities as a Frontend Developer
Favicon
🚀 Introducing DataForge: A Laravel-Based Framework to Transform Backend Development
Favicon
Python's Unstoppable Rise, Dominating The Modern Backend Environment
Favicon
[Boost]
Favicon
How to write Simple Endpoint and Functions
Favicon
Effortless AI Model Integration: Build and Evaluate AI Models (Spring Boot and Hugging Face)
Favicon
Email Verifier using Go
Favicon
No Swagger in .NET 9? Here's What You Need to Know!
Favicon
Microservice communication using Kafka
Favicon
[Volunteer Opportunity] Back-End Developer Needed for a EU Uni Finder/Helper Project 🚀
Favicon
Dart server-side framework for solo project
Favicon
I need a partner, who's interested in making the backend of a messaging app, for free though. Thanks, in advance 😃🙂. Contact me at [email protected]
Favicon
503 errors
Favicon
Top 6 Reasons to Partner with Experts in Mobile App Design and Backend Development
Favicon
Pointers in C Programming - Lay Man's Analogy
Favicon
Navigating the Web Development Landscape: Finding Your Role
Favicon
Excited to Be Part of This Community! 🚀

Featured ones: