Pointers Basic Of Pointer • int x=5; For Example     main() {      int x=5; Printf("%d\n",X); printf("%d&qu...

Pointers ( Most Important Topic) In C Programming Language.

Pointers

Basic Of Pointer

• int x=5;

For Example

    main()

{

     int x=5;

Printf("%d\n",X);

printf("%d",&X);

}

Output Screen


Address Of Opertor

• & is known as address of operator.

• It is an unary operator.

• Operend must be the name of variable.

• & operator gives the address number of variable.

• & is also known as referencing operator

• (Address and reference are same).

Indirection Operator

• * is indirection operOper.

• It is also known as defrencing operator.

• It takes address as an argument.

• * returns the content (container whose address is its argument)


Example

  main()

{

  int x=5;

printf("%d \n",x);

printf("%d",*&x);

printf ("%d",*&x);

}

• % 32768 to 32767

• %u  0 to 65535

Question

int x=5;

 &x = 7;

            ↘(Error)

Because we can't store anything in &x as &x is not a variable it is the way to represent address of block x.

But 

  int x=5;                

     j=&x;

We can store address in another variable but 'j' has to be declared before use.


Pointer

  int *j, x=5;  /* Here (*) symbol is denoted as pointer */

  j=&x;

• j is not an ordinary variable like another integer variable.

• It is a variable which contains the address of another variable.

Definition of Pointer

• pointer is a variable which that contains address of another variable.

• Pointer always consumes 2 bytes memory.


Example

main()

{

   int x = 5; *j;

  j= &x;

printf("%d %d\n",x,j);

printf("%d %d",*j,&x);

printf("%d", *&j);

}


Output 


Base Address

 int a,*j;

 float b,*k;

char c, *r;

So in the pointer 

j=&a;  k=&b; c=&c;

{Whenever we will enter float data type or other data type value should be in the form of float otherwise

It will give error in C language.}

This was the basic concepts of pointer I hope guys this article would be helpful for you.


0 Comments: