element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Blog Back to College: C Language Operators
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: phoenixcomm
  • Date Created: 30 Sep 2018 10:25 AM Date Created
  • Views 2300 views
  • Likes 8 likes
  • Comments 6 comments
  • Code Exchange
  • operators
  • back to college
  • arduino_tutorials
  • c programing language
Related
Recommended

Back to College: C Language Operators

phoenixcomm
phoenixcomm
30 Sep 2018

I will not stutter. C is one of the most powerful computer languages ever written. In this blog, I will show what an operator is.

An operator in its simplest form would be: a added to b. In this case, the operator is added to. But you also have an assignment operator in its simplest form would be a assigned to b.  In this case, the operator is assigned to.

But in C we also have a compound opeator. In most cases they are used every day they are a rich set of operators. Such as ++i, (pre-inc),  i++ (post-inc) and as well as +=, -=, *=, /=, and %=.

So the proper use of a compound operator += would be a += b  is the same as a = a + b. In the case of the increment operator, may be used on either side of the equation. So i++ is saying i = i + 1, that is incrementing the value of i. i++ of course has its true opposite i -- where i = i - 1. So in fact this is quite legal: a++ = b++ + ++c;  So lets apply some numbers to this a, b, c are all going to be 0.  as the compiler evaluates this mess (this is a extreem example and hope never to see it in the wild).

  1. c is pre-incremented to 1
  2. then it adds b + c  and stores it in a or a = 0 + 1 so c is now 1
  3. then it post-increments a and b to 1
  4. final values are a = 2, b = 1, c = 1.

The Railroad Tracks or BNS (Backus-Naur Form) for the C Language

This grammar was adapted from Section A13 of The C programming language, 2nd edition, by Brian W. Kernighan and Dennis M. Ritchie,Prentice Hall, 1988.

<unary-expression> ::= <postfix-expression> | ++ <unary-expression> | -- <unary-expression> |

<unary-operator> <cast-expression> | sizeof <unary-expression> | sizeof <type-name>

 

<postfix-expression> ::= <primary-expression> | <postfix-expression> [ <expression> ] |

<postfix-expression> ( {<assignment-expression>}* ) | <postfix-expression> . <identifier> | <postfix-expression> -> <identifier> | <postfix-expression> ++ | <postfix-expression>

 

<unary-operator> ::= & | * | + | - | ~ | !

 

<expression> ::= <assignment-expression>  | <expression> , <assignment-expression>

 

<assignment-expression> ::= <conditional-expression>  | <unary-expression> <assignment-operator> <assignment-expression>

 

<assignment-operator> ::= = | * |  /=  | %=  | +=  | -=  | <<=  | >>=  | &=  | ^= | |=

 

This information is given to any student in school who learns C.  For instance by reading this chapter of the book you know that C does not have a square operator such as other languages (sometimes written as ** or ^) so what do we as C programmers do? Hey let the Pre-Processor do it:

#define sq(x) ((x)*(x)) and that it. You could also have done this as a function. Why the Pre-Processor and not a function: works on any data type int, float the compiler never sees it and best there is no CALL/RETURN on the stack.

 

Abuse and Tests:  

x= ++i + ++i + ++i;

This is a question that I commented on earlier. The person giving the test knows that your answer should be "This is not legal C Language syntax",  If you try an answer this hot mess he knows that you do not know C that well.   To put this in perspective I never took the Introduction to The C Language.

  • Sign in to reply

Top Comments

  • Fred27
    Fred27 over 6 years ago +3
    I saw this exact thing over on eevblog.com recently. Was that you posting there too? Also, even if it was valid C, nobody should ever write really terse code like this. Some people do because they think…
  • phoenixcomm
    phoenixcomm over 6 years ago in reply to dixonselvan +2
    Thank you Dixon, you just have to remember that any of the group in this class is considered a unary operator where I said that x = i++ + i++; is not a valid construction as both sides of the operator…
  • shabaz
    shabaz over 6 years ago in reply to Fred27 +2
    Indeed, it doesn't matter to most users of languages, if it's legal with a 1990's or modern day compiler or not (this was the root of the original question that prompted this), because it would still get…
Parents
  • dixonselvan
    dixonselvan over 6 years ago

    Thank you for sharing Cristina Harrison phoenixcomm I've been questioned about incremental operator the post and pre versions in interviews. Your post has been a good refresher. Is this a collection of posts? Will you be continuing this kind of posts?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • phoenixcomm
    phoenixcomm over 6 years ago in reply to dixonselvan

    Thank you Dixon, you just have to remember that any of the group in this class is considered a unary operator where I said that x = i++ + i++; is not a valid construction as both sides of the operator image  are incrementing the same value (the compiler will go a little nuts) now if it x = i++ + a++; or any other variable that would work. Now to your kind question. Yes/No At Blog Index i  there is an alphabetic index, my field is, flight simulation. But I write about anything. If you follow the links to Tutorials at NexGen Simulator Blog Index iii, You will find some others.

    If you like physics go to NexGen Blog Index ii and look at "Simulator 101 or back to College" this has to do with the math of the earth, and how we use it.

    But If you would like me to do a post on a subject please feel free to submit a request to me. (informal note will do, LOL)

    Currently learning Java 8, and will be looking a modeling language papyrus-rt, and a very small language that is overlooked but is very small and designed to be embedded. LUA which is neat as you can use it as a scripting language. I also have worked with Perl, and some assemblers notably   BAL (IBM360), Z80, 6800 and 68K. I have messed about with python but will not use it as its a through back to Fortran, where columns mater.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • phoenixcomm
    phoenixcomm over 6 years ago in reply to dixonselvan

    Thank you Dixon, you just have to remember that any of the group in this class is considered a unary operator where I said that x = i++ + i++; is not a valid construction as both sides of the operator image  are incrementing the same value (the compiler will go a little nuts) now if it x = i++ + a++; or any other variable that would work. Now to your kind question. Yes/No At Blog Index i  there is an alphabetic index, my field is, flight simulation. But I write about anything. If you follow the links to Tutorials at NexGen Simulator Blog Index iii, You will find some others.

    If you like physics go to NexGen Blog Index ii and look at "Simulator 101 or back to College" this has to do with the math of the earth, and how we use it.

    But If you would like me to do a post on a subject please feel free to submit a request to me. (informal note will do, LOL)

    Currently learning Java 8, and will be looking a modeling language papyrus-rt, and a very small language that is overlooked but is very small and designed to be embedded. LUA which is neat as you can use it as a scripting language. I also have worked with Perl, and some assemblers notably   BAL (IBM360), Z80, 6800 and 68K. I have messed about with python but will not use it as its a through back to Fortran, where columns mater.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • shabaz
    shabaz over 6 years ago in reply to phoenixcomm

    LUA was something that interested me too, but Python has a lot of traction in some lines of work that I end up in, so I can't avoid having to get used to it a bit. I feel the same about the indentation thing you mention!

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube