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:

1
2
3
4
5
6
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.

Example:
1
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.

Comments

Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

Hackerrank > SQL > Basic Select

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
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as

Zoho Puzzle Questions With Answers

Measuring Time Logic Puzzle You are given with two ropes with variable width. However if we start burning both the ropes, they will burn at exactly same time i.e. an hour. The ropes are non-homogeneous in nature. You are asked to measure 45 minutes by using these two ropes.

How can you do it?

Please note that you can’t break the rope in half as it is being clearly stated that the ropes are non-homogeneous in nature.
Answer & Explanation Solution: 45 minutes

Explanation :
All you have to do is burn the first rope from both the ends and the second rope from one end only simultaneously. The first rope will burn in 30 minutes (half of an hour since we burned from both sides) while the other rope would have burnt half. At this moment, light the second rope from the other end as well. Where, the second rope would have taken half an hour more to burn completely, it will take just 15 minutes as we have lit it from the other end too.

Thus you have successfully calculated 30+15 = 45 minutes …