What is syntactic sugar?

In programming, the term syntactic sugar is used to describe some syntax that is meant to make some part of a programming language easier to read and express. Syntactic sugar means that the syntax does not actually add any extra functionality to the programming language – it’s really just an alternative syntax that’s easier for humans to read and use. The reason it’s called “sugar” is to make the experience of reading and using the programming language “sweeter” and easier for people.

An example of syntactic sugar

Suppose we have a structure in C that we will call someStruct. And, let’s say that someStruct has a member variable that we can call memberVariable. Now, we can access that member variable using this syntax:


But, if we want to use some syntactic sugar instead, then we can just write it like this instead:


Clearly, the second option is much easier to understand than the first. And that is our example of syntactic sugar in C.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.