
- C Programming
- introduction of c language
- Introduction of C programming
- what is Array and types of arrary
- Basic Structure of C Program
- C Program to Generate Multiplication Table
- C Programming Operators and Expressions
- Data Types In C Programming
- C Keywords and Identifiers
- Types of Arrays in C Progarmming
- pointer in c language
- C program to print patterns of numbers and stars
pointer in c language
The Pointers in c language programming is a variable that points to the address of another variable. The Pointer in the C language is used to indicate the memory randomly for example at the run time. pointer variable strength is comfortableness to any of data type such as int for digits, float for decimal, char, double character, short, etc. Computer science is the programming language object, whose value refers to another value stored elsewhere in computer memory using its memory address. A pointer references the location in the memory, and achieving the value stored at that location is known as a dereferencing pointer. The Pointer Syntax: data type*var name for example int *p; char *p;.
KEY POINTS TO REMEMBER The POINTERS IN The C
- The size of any pointer is 2 bytes (8 bits).
- The Pointer addition, multiplication, and division are not allowed.
- If the pointer in the C language is assigned to a NULL value then, it means it is indicating nothing.
- 2 pointers can be deducted or reduced to know how many elements are present between these two pointers.
- * sign is used to achieve the value of the variable that the pointer is pointing to.
- & sign is used to get the address of the variable.
- C pointer is initialized to null, for example, int *p = null.
- value of the null pointer is 0
- medium variable stores the value whereas the pointer variable stores the address of the variable.
Types of pointers
Different types of pointers in c language are as follows.
- Huge Pointers.
- Near Pointer.
- Far Pointer.
- Complex Pointers.
- Generic Pointers.
- Wild Pointer.
- NULL Pointer.
- Dangling Pointer.
Huge pointer
Huge pointer access whole the residence memory of the RAM for example which can access all sixteenth segments is known as a huge pointer. The huge pointer takes or reserves 32 bits or 4 byte in memory.
illustration of Huge Pointer in C Programming
#include<stdio.h>
int main()
{
int a = 25;
int huge *ptr_var;
*ptr_var = &a;
printf(“\nThe Size of Huge Pointer:\t\t%d”, sizeof(ptr_var));
return 0;
}
Near Pointer
a pointer that can indicate or point only 64 KB (kilobyte) of data piece is known as a near pointer. The pointer is near pointer does not achieve beyond data pieces like graphics video memory or text video memory, etc. The Size of the near pointer is 2 bytes.
#include<stdio.h>
int main()
{
int a = 10;
int near *ptr_var;
*ptr_var = &a;
printf(“%d”, sizeof(ptr_var));
return 0;
}
Far pointer
The far pointer can point to the whole residence memory of RAM, for example, which can access all sixteenth pieces is known as a far pointer. The Size of the far pointer is 4 bytes (32 bit) of data one bit can store one character of data in one byte there are 8 bits that can store 8 characters of data or alphabets.
Code example of Far Pointer in C Programming
#include<stdio.h>
int main()
{
int a = 10;
int far *ptr_var;
*ptr_var = &a;
printf(“%dThe size of “, sizeof(ptr_var));
return 0;
}
Generic Pointers
The generic pointer is very useful when we are wanted to point to any type of data the generic pointer is used to point data. When the variable is initialized or declared as being the pointer to type (main functions of c language) void is known as the generic pointer. Since we cannot have the variable of type void, the Generic pointer will not point to any data and therefore cannot be dereferenced. It is currently the pointer though, to use it we just have to cast it to the next type of pointer first.
Code example of Generic Pointer in C Programming
int
main()
{
int i;
char c;
void *the_data;
i = 6;
c = ‘a’;
the_data = &i;
printf(“Data points to the integer value %d\n”, *(int*) the_data);
the_data = &c;
printf(“Data now points to the character %c\n”, *(char*) the_data);
return 0
;
}
Wild Pointer
The Pointer in the C language that has not initialized till its first use is known as the wild pointer. the wild pointer indicates to some random memory location in the c language where we want to point the data.
Code example of Wild Pointer in C Programming
#include<stdio.h>
int main()
{
int *ptr;
printf(“%p\n”, ptr);
printf(“%d”, *ptr);
return 0;
}
NULL Pointers
The Pointer which is declared with the NULL value is known as the NULL pointer,Null pointer in the pointer is the pointer that is pointing to nothing. The Null pointer points to the base address of any segment. The Null pointer is the micro constant prescribed in the following header files which are, stdio. h,etc.
Code example of NULL Pointer in C Programming
#include <stdio.h>
int main()
{
int *ptr_f = NULL;
int *ptr_s = 0;
printf(“\nfirst Pointer:\t%p\n”, ptr_f);
printf(“\nsecond Pointer:\t%p\n”, ptr_s);
return 0;
}
The Dangling pointers is awaken when the object is deleted, without changing the value of the pointer, Therefore the pointer still points to the memory location of the deleted memory.
Illustration of Dangling Pointer
char *user_function(void)
{
char ch = ‘D’;
return &ch;
}
MORE ABOUT POINTERS |
---|
Void Pointers |
Near Pointers |
Far Pointers |
Huge Pointers |
Function Pointers |
Wild Pointers |
Null Pointers |
Dangling Pointers |