Saturday, July 28, 2012

How To Read Complicated Declarations In C Language

Friends as you all know that  some declarative statements are very easy but declarative statements that contains pointer and functions are little bit complicated. Today i will tell you some steps to read  such complicated statements,after read these steps you can easily understand all the complicated statements.Its my promise:):):)


So concentrate here and try to understand all the steps.


http://www.learning-tutorials.blogspot.com






1) Convert C declaration to postfix format and read from left to right.



2) To convert experssion to postfix, start from innermost parenthesis, If innermost parenthesis is not present then start from declarations name and go right first. When first ending parenthesis encounters then go left. Once whole parenthesis is parsed then come out from parenthesis.
3) Continue until complete declaration has been parsed.
For ex:
          int (*fp) ();
Let us convert above expression to postfix format. For the above example, there is no innermost parenthesis, that’s why, we will print declaration name i.e. "fp". Next step is, go to right side of expression, but there is nothing on right side of "fp" to parse, that’s why go to left side. On left side we found "*", now print "*" and come out of parenthesis. We will get postfix expression as below.
   fp  *  ()  int
Now the statement become simple and you can say that fp is pointer to function returning int(read from left to right).
Also See This:





***Thanks Friends***

No comments:

Post a Comment

Please Give Me Your Views

Popular Posts