Pointers Introduction in C

A variable in a program is something with a name of a memory location in which a value is stored. The way the compiler and linker handles this is that it assigns specific bytes of memory within the computer to hold the value of that variable. The size of that block of memory depends on the range over which the value of the variable is allowed to vary. For example, on PC’s the size of an integer variable is 2 bytes.

When a variable is declared, the computer is informed of two things: the name of the variable and the type of the variable. For example, a variable of type integer with the name k will be written as:

int k;

Then the compiler reserves 2 bytes of memory to hold the value of the integer.

K = 2;

denotes the value 2 will be stored in the memory location reserved for k.

There are two values associated with k. One is the value of the integer stored and the other the memory location, i.e., the address of k. These two values are referred with the nomenclature rvalue and lvalue respectively. In other words, the lvalue is the value permitted on the left side of the assignment operator = (i.e. the address where the value of evaluation of the right side ends up), and the rvalue is that which is on the right side of the assignment statement. rvalues cannot be used on the left side of the assignment. Thus

2=k;

is an illegal statement in C. According to K&R “An object is a named region of storage; an lvalue is an expression referring to an object”.

A pointers are basically a variable same as any other variable. However, that is different about them is that instead of containing actual data, they contain the memory location where actual information is stored. A pointer variable is variable which will store the address of another variable. Pointers are used frequently in C, as they have a number of useful applications. The following are some usages of pointer.

  • • Cannot data structures in memory (lists, chains, queues, tress, graphs)
  • • Allows a function to modify its arguments
  • • The concept of dynamic memory is implemented.
  • • Concise and efficient array access
  • • Efficiently pass structure to a function


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext