Difference between Pointer and Ordinary Variable in C

In C programming, pointers and normal variables both store data, but they work in different ways. A normal variable stores a value directly, like a number. A pointer, on the other hand, stores the memory address of another variable. This makes pointers useful for more advanced tasks like working with arrays or functions.

What is an Ordinary Variable in C?

An ordinary variable in C is a named storage location that holds a specific type of data, such as integers, characters, or floating-point numbers. When you declare a variable, the compiler allocates memory to store its value.​

Example:

int score = 80;

Here, score is an integer variable that stores the value 80.​

What is a Pointer in C?

A pointer is a variable that stores the memory address of another variable. Instead of holding a direct value, it holds the location where the value is stored in memory. This allows for indirect access and manipulation of variables.​

advertisement

Example:

int score = 80;
int *ptr = &score;

In this example, ptr is a pointer to an integer, and it stores the address of the variable score.​

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

Difference Between Pointer and Ordinary Variable in C

Here are the key differences between pointers and normal variables in C:

Aspect Ordinary Variable Pointer Variable
Definition Holds a direct value (like an integer, float, char, etc.) Holds the memory address of another variable
Data Stored Actual data or value Address of a variable
Declaration int mcq; int *p;
Accessing Value Directly using the variable Indirectly using * (dereferencing)
Symbol Used No special symbol * for dereferencing, & to get address
Memory Use Stores only the value Stores the address, and can access/manipulate other variables
Example int score = 90; int *ptr = &x;
Use Case For normal storage and calculations For dynamic memory, function arguments (pass by reference), data structures like linked lists
Modifying Data Changes only the current variable Can modify the variable it points to
Nullability Always stores a valid value Can be NULL if not pointing to anything

Code Example

#include <stdio.h>
 
int main()
{
    int mcq = 5;           // ordinary variable
    int score;             // another ordinary variable
    int *quiz;             // pointer to an int
 
    score = mcq + 3;       // direct use of value
    quiz  = &score;        // store address of 'score'
 
    printf("mcq: %d\n", mcq);                // 5
    printf("score: %d\n", score);            // 8
    printf("quiz (addr): %p\n", (void*)quiz); // e.g. 0x7ffe…
 
    // Using pointer to change score
    *quiz = 12;            // indirect assignment via pointer
    printf("score now: %d\n", score);        // 12
 
    return 0;
}

Output:

mcq: 5
score: 8
quiz (addr): 0x7ffdbc0a0778
score now: 12

This program shows how pointers work in C. It starts with two normal variables, mcq and score. Then it creates a pointer quiz that stores the address of score. The program prints the values and address. Using the pointer, it changes the value of score to 12. This shows how pointers can change values by pointing to their memory location.

When to Use Pointers vs Ordinary Variables in C

When to Use Ordinary Variables

  • Ordinary variables are best when storing simple values like int, char, or float.
  • They work well for basic operations where dynamic memory isn’t required.
  • If your data is small or fixed in size, memory efficiency isn’t a concern.
  • Use them when passing values to functions that don’t need to alter the original data.
  • They are ideal for static arrays or strings that don’t require resizing.
  • In general, ordinary variables are suitable for simple programs and basic calculations.

When to Use Pointers

  • Pointers are useful when you need to manipulate data indirectly, such as modifying values inside a function.
  • They are essential for dynamic memory allocation using functions like malloc() or calloc().
  • For large data structures like arrays or structs, pointers allow you to pass data efficiently to functions.
  • They are crucial when building complex structures like linked lists, trees, or graphs.
  • Pointers also allow functions to return multiple values through references.
  • When working with arrays or strings, pointer arithmetic can improve performance and flexibility.
  • Finally, for low-level memory access—especially in systems or embedded programming—pointers are indispensable.

Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

advertisement
If you wish to look at all C Tutorials, go to C Tutorials.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.