C – Pointers

After Reading Pointers topic, you will able to use it in C programming, you will understand the theory and example also you will able to use pointer operators in C programming.

In C programming, every variable stored in a memory (RAM), and every memory location has its own unique address and the data stored at this location could also be accessed through the address instead of their variable name. This is the idea behind Pointer.

C pointer is a variable which holds the memory address of another variable and hence the pointer can be used for data manipulation which further reduces execution time. The memory address is positive integer written in Hexadecimal format.

Let us assign the address of variable A to variable B, using statement B = &A and assume that the address of B is 5000. The symbol & named as ampersand represent address operator in C programming. The relation between A and B can be represented as shown

Here the value of variable B is the address of variable A and variable B is called the pointer.

Pointer operators

Two operators used with a c pointer are

  • The Address Operator (&).
  • The Indirect Operator or Dereferencing operator (*).

Address Operator (&)

The address of any variable can get by using an ampersand (&), placing in the prefix of the variable name. The example below will show you how to use Address operator in C programming.

Indirection Operator or Dereferencing Operator (*)

The indirection operator used to give the value of the variable whose address stored in a pointer and hence indirection operator is also referred as a value at address operator.

The example below will show you how to use Indirection Operator in C programming.

Program (1): To demonstrate the use of Address operator and Indirection operator in C programming.

#include<stdio.h>
#include<conio.h>
void main(void)
{
int i=10;
int *k;
printf("value of i = %d",i);
printf("n%lu is address of i.",&i);
k=&i;
printf("nvalue of k = %lu",k);
printf("n%d is value of i.",*k);
getch();
}

Output (1)

value of i = 10
1703752 is address of i.
value of k = 1703752
10 is value of i.C

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *