Right Click to Search

Friday, August 6, 2024

How to Read Complex and Difficult Pointer in C Programming ?


Before We Learn How to Read Complex Array we should first know precedence and associative .
  • Precedence : Operator precedence describes the order in which C reads expressions
  • Associativity : Order operators of equal precedence in an expression are applied
Before Reading Article You Should know Precedence and Associative Table
OperatorPrecedenceAssociative
(),[]1Left to Right
*,Identifier2Right to Left
Data Type3-

Different Terms From Table -
()Bracket operator OR function operator.
[]Array subscription operator
*Pointer operator
IdentifierName of Pointer Variable
Data typeType of Pointer

How to Read ?
char (* ptr)[5]

Step 1 :
  • Observe Above Precedence Table
  • [] and () have Same Priority
  • Using Associativity , Highest Priority Element is decided
  • Associativity is from Left to Right First Priority is Given to "()"
Step 2 :
  • Between Pair of Brackets again we have to decide which one has highest priority ? '*' or 'ptr' ?
  • * and Identifier ptr have Same Priority
  • Associativity is from Right to Left First Priority is Given to "ptr"
Step 3 :
  • Assign third Priority to [].
  • Write 3 under []
Step 4 :
  • Here Char is Data Type
  • Assign Priority 4 to char
Read it as -
ptr is pointer to a one dimensional array having size five which can store data of type char

Tags / Keywords : | ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates