Understanding Prefix & Postfix Operators

I just started my journey to learn how to build mobile apps with @ingressive4Good and @thezuriteam who are providing free software development and design trainings to young people all over Africa. I joined the Kotlin (Java) track and have been leveraging SoloLearn for Java lessons and Replit to practice.

On getting to Operators on SoloLearn, I found prefix and postfix operators a little confusing. The difference between what happens when the operator is before and after the operand seemed a bit strange. So I practiced a bit on my Replit scratchpad and arrived at a way to correctly interpret their actions:

  • prefix: take action (increment or decrement) on operand first before doing any other thing.
  • postfix: take action on operand after doing every other thing.

The interesting part of this story is that I tried to see if I was the only one who found this challenging. I posted a poll with a simple problem and was both surprised and relieved by the result. Even though only a few person voted, they all got the answer wrong!

图片[1]-Understanding Prefix & Postfix Operators - 拾光赋-拾光赋 Etekah Enameti @etekahe
What is the output of this code snippet?

int n = 64;

System.out.println(n++);

#Java
#100DaysOfCode 18:47 PM – 01 Apr 2021
图片[2]-Understanding Prefix & Postfix Operators - 拾光赋-拾光赋
图片[3]-Understanding Prefix & Postfix Operators - 拾光赋-拾光赋

Do you really know how prefix and postfix operators work? Think again!

原文链接:Understanding Prefix & Postfix Operators

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容