
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What are the different types of pointers in C language?
The pointer is a variable that stores the address of another variable.
The syntax for the pointer is as follows −
pointer = &variable;
Types of Pointers
There are eight different types of pointers which are as follows −
Null pointer
Void pointer
Wild pointer
Dangling pointer
Complex pointer
Near pointer
Far pointer
Huge pointer
Null Pointer
You create a null pointer by assigning the null value at the time of pointer declaration.
This method is useful when you do not assign any address to the pointer. A null pointer always contains value 0.
Example
Following is the C program for the null pointer −
#include <stdio.h> int main(){ int *ptr = NULL; //null pointer printf("The value inside variable ptr is:
%d",ptr); return 0; }
Output
When the above program is executed, it produces the following result −
The value inside variable ptr is: 0
Void Pointer
It is a pointer that has no associated data type with it. A void pointer can hold addresses of any type and can be typecast to any type.
It is also called a generic pointer and does not have any standard data type.
It is created by using the keyword void.
Example
Following is the C program for the void pointer −
#include <stdio.h> int main(){ void *p = NULL; //void pointer printf("The size of pointer is:%d
",sizeof(p)); //size of p depends on compiler return 0; }
Output
When the above program is executed, it produces the following result −
The size of pointer is:8
Wild Pointer
Wild pointers are also called uninitialized pointers. Because they point to some arbitrary memory location and may cause a program to crash or behave badly.
This type of C pointer is not efficient. Because they may point to some unknown memory location which may cause problems in our program. This may lead to the crashing of the program.
It is advised to be cautious while working with wild pointers.
Example
Following is the C program for the wild pointer −
#include <stdio.h> int main(){ int *p; //wild pointer printf("
%d",*p); return 0; } Process returned -1073741819 (0xC0000005) execution time : 1.206 s Press any key to continue i.e. you won’t get output, some compilers show error message at output
- Related Articles
- What are the different types of keywords in C language?
- What are different types of constants in C language?
- What are different types of data in C language?
- What are different pointer operations and problems with pointers in C language?
- What are pointers to structures in C language?
- Explain the concept of pointers in C language
- What are types of expressions evaluated in C Language?
- What are the different searching techniques in C language?
- What are different types of constants in C++?
- What are primary data types in C language?
- Demonstrate the concept of pointers using C language
- What are the different data types of arrays in C#?
- What are the different types of functions in C Programming?
- Explain array of pointers in C programming language
- What are the different operations on files in C language?
