Skip to main content

Types of C pointers

  1. NULL Pointer
  2. Dangling Pointer
  3. Generic Pointers
  4. Wild Pointer
  5. Complex Pointers
  6. Near Pointer
  7. Far Pointer
  8. Huge Pointers

NULL Pointer :

Literal meaning of NULL pointer is a pointer which is pointing to nothing. NULL pointer points the base address of segment.

Examples of NULL pointer:

int *ptr=(char *)0;
float *ptr=(float *)0;
char *ptr=(char *)0;
double *ptr=(double *)0;
char *ptr=’\0;
int *ptr=NULL;

NULL is macro constant which has been defined in the heard file as :
#define NULL 0

Dangling pointer :

If any pointer is pointing the memory address of any variable but after some variable has deleted from that memory location while pointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem.

Generic pointer :

void pointer in c is known as generic pointer. Literal meaning of generic pointer is a pointer which can point type of data.

void *ptr;

Here ptr is generic pointer.

  • We cannot dereference generic pointer.
  • We can find the size of generic pointer using sizeof operator.
  • Generic  pointer can hold any type of pointers like char pointer, struct pointer,  array of pointer etc without any typecasting.
  • Any type of pointer can hold generic pointer without any typecasting.
  • Generic pointers are used when we want to return such pointer which is  applicable to all types of pointers. For example return type of malloc  function is generic pointer because it can dynamically allocate the  memory space to stores integer, float, structure etc. hence we type cast  its return type to appropriate pointer type.

Wild pointer :

A pointer in c which has not been initialized is known as wild pointer.

Complex pointer :

  1. Pointer to function  
  2. Pointer to array
    • Pointer to array of integer
    • Pointer to array of function
    • Pointer to array of character
    • Pointer to array of structure
    • Pointer to array of union
    • Pointer to array of array
    • Pointer to two dimensional array
    • Pointer to three dimensional array
    • Pointer to array of string
    • Pointer to array of pointer to string
  3. Pointer to structure
  4. Pointer to union
  5. Multilevel pointers

In TURBO C there are three types of pointers. TURBO C works under DOS operating system which is based on 8085 microprocessor.

1.  Near pointer
2.  Far pointer
3.  Huge pointer

The pointer which can points only 64KB data segment or segment number 8 is known as near pointer.

The  pointer which can point or access whole the residence memory of RAM  i.e. which can access all 16 segments is known as far pointer.

The  pointer which can point or access whole the residence memory of RAM  i.e. which can access all the 16 segments is known as huge pointer.


Popular posts from this blog

C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
int const * p=5; printf("%d",++(*p));
Compiler error: Cannot modify a constant value.
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
Answer: mmmm
aaaa nnnn

Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
    1. Booking
    2. Availability checking
    3. Cancellation
    4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

 My Solution :

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>#include<iostream.h>#include<time.h>#include<iomanip.h>#include<fstream.h>char f[10]="f";char s[10]="s";int addr,ad,flag,f1,d,m,i,amt;float tamt; class login {public:char id[100];char pass[100];char*password;void getid(){ cout<<"Enter your id:";gets(id); password=getpass("Enter the password:");strcpy(pass,password);}void displayid(){ cout<<"Id:";puts(id); cout<<"Password:";puts(pass);}}; class detail {public:in…

Hackerrank > SQL > Basic Select

01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
02-Select by ID
Given a City table, whose fields are described as