Types of Pointer in C Programming Language

Rumman Ansari   Software Engineer   2019-03-31   9385 Share
☰ Table of Contents

Table of Content:


pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address. The general form of a pointer variable declaration is ?

type *var-name;

What is a pointer in C programming?

A pointer is a user-defined data type which creates special types of variables which can hold the address of primitive data type like char, int, float, double or user-defined data type like function, pointer, etc. or derived data type like an array, structure, union, enum.

Examples:

int *ptr;

int (*ptr)();

int (*ptr)[2];

Important points about pointer?

  • In computer science, a pointer is a programming language object, whose value refers to (or “points to”) another value stored elsewhere in the computer memory using its memory address. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer.
  • A pointer is a variable which contains the address in memory of another variable. We can have a pointer to any variable type.
  • The unary or monadic operator & gives the “address of a variable”.
  • The indirection or dereference operator gives the “contents of an object pointed to by a pointer”.

The general form of a pointer variable declaration is ?

type *var-name;

Here, the type is the pointer’s base type; it must be a valid C data type, and var-name is the name of the pointer variable. The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement, the asterisk is being used to designate a variable as a pointer. Take a look at some of the valid pointer declarations ?

int    *ip;    /* pointer to an integer */
double *dp;    /* pointer to a double */
float  *fp;    /* pointer to a float */
char   *ch     /* pointer to a character */

type *var-name;

Types Of Pointers In C Programming

  • NULL Pointer
  • Dangling Pointer
  • Generic Pointers
  • Wild Pointer
  • Complex Pointers
  • Near Pointer
  • Far Pointer
  • Huge Pointers