• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Pointers and their Rules in C

Pointers and their Rules in C Language

Arithmetic operation on pointers

 

int i1,i2;

in t*p1,*p2;

p1=&p1;

p2=&p2;

 

  1. p1+p2; error
  2. p1+1, Next address
  3. ++p1,p1++ = Next Address
  4. p2-p1 No of elements
  5. p2-1; previous elements address
  6. – -p2, Previous Address
  7. p1*p2; error
  8. p1*5; error
  9. p1/p2; error
  10. p1/p2; error
  11. p1%p2; error
  12.  p1%2.error p2- –

 

 

Pointer rules :-

Rule 1:

Address + Number = Address (Next Address)

Address – Number  = Address(pre Address)

Address ++=Address(Next address)

Address–=Address(Pre Address)

++ Address= Address(Next Address)

–Address = Address(Pre address)

 

Rule  2:-

Address – Address = Number(No.of elements)

= size diff/sizeof(datatype)

int*p1=(int*)100;

int*p2=(int*)200;

p2-p1=50

200-100 ——- > 100/size of(int)

 

Rule 3:

Address + Address=Illegal.

Address * Address= illegal

Address/Address= illegal

Address%Address=illegal

 

Rule 4:

We can use relational operator and conditional operator b/w two pointers(<,>,<=,>=,==,!=,?!)

Address  > Address = T/F

Address  > = Address = T/F

 

Rule 5:      

We can’t perform bitwise operation b/w two pointers like

Address & Address = illegal

Address | Address=Illegal

Address ^ Address = illegal

~ Address=illegal

 

Rule 6:

We can find size of a pointer using size of operator.

 

 

 

 

 

 

 

Summary
Review Date
Reviewed Item
Pointers and their Rules in C
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Pointers and their Rules in C"

Leave a Message

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

Site Disclaimer, Copyright © 2016 - All Rights Reserved.