0 bradleydoorly61 November 25, 2020

A pointer is a variable thta conatins a memory address of data or another variable. Normally, a pointer variable is declated to some type, like any other variables, so thta it will work only with data of given type. 

The syntax of pointer is

data_type *pointer;

Pointer Declaration

int *x;

In the first statement, x is an integer pointer and it tells to the compiler that it holds the address of any int variable.

Adress Operator

The operator & is known as aqddress operator. Thus &a denotes the address of variable a.

Lets take an example to make clear concepts on pointer.

#include <stdio.h> 

int main() 
	int var = 20; 
	// declare pointer variable	 
	int *ptr; 
	// note that data type of ptr and var must be same 
	ptr = &var;	 

	// assign the address of a variable to a pointer 
	printf("Value at ptr = %p \n",ptr); 
	printf("Value at var = %d \n",var); 
	printf("Value at *ptr = %d \n", *ptr);	

The output of the above program is:

Value at ptr = 0x7ffc5ac79fbc 
Value at var = 20 
Value at *ptr = 20 

In the next tutorials, We will learn how to use pointers and array.