Pointer | C Language | Start your journey with C | Part 8

Pointer in C Language:

Pointer which store address of variables .
All variable have address whether it is int , char , float ,double 0 to 65535 address of memory block . 

Integer in pointer :



Character pointer in array:

NOTE : Addresses in an array will change according to data type . For example : 

Integer pointer pointer in array: Address will change by increment or decrement of 2
Float pointer in array: Address will change by increment or decrement of 4

& Operator :

&(address) Operator is use for address of variable for output and input perpose . It is a unary operator also known as referencing operator.

* Operator : 

*(indirection) Operator is use to store address of variable. It is a unary operator also known as de-referencing operator.

Basic syntax :

 Sample 1 : Address , value in pointer.

#include<stdio.h>
void main()
{
int a=5,*p;
 p=&a;
 printf("%d\n",a); //value of variable
 printf("%d\n",&a); //address of variable
 printf("%d\n",p); //value of address in pointer 
 printf("%d\n",&p); //address of pointer as variable
 printf("%d\n",*p); //value of variable through address
}

Sample 2 : Pointer in array

#include<stdio.h>
void main()
{
 int a[5],*p,i;
 printf("Enter the elements upto five:\n");
 p=&a[0];
 for(i=0;i<4;i++)
     { scanf("%d",(p+i)); }
 for(i=0;i<4;i++)
      { printf("%d",*(p+i)); }
} 

Output:
Enter the elements upto five:
7
2
8
3
4
72834
--------------------------------------------------------

Start your Journey with C | Part-2

Start your Journey with C | part-1

Start your Journey with C | Part-3

 

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :