Загрузка...

99℅ of Beginners Fail this Simple Java Math..Can you guess the output? #devjava #facts #coding

Most people see x = x++ and instantly think 6. But the answer is actually 5! Here is exactly why:

When you use the post-increment operator (x++) combined with an assignment (=):
1️⃣ Java remembers the original value of x (which is 5) and holds it temporarily.
2️⃣ It increments the actual x variable to 6 in the background.
3️⃣ The assignment = operator kicks in and overwrites x with that original, temporarily saved value (5)!

To actually make it 6, you just need to write x++; by itself, or use pre-increment: x = ++x;

Did you guess 5 or 6 at first glance? Be honest in the comments!

Follow @DevDotJava to build your logic and master Java & DSA from scratch!

#JavaProgramming #CodingLife #LearnToCode #Developer #TechTips #CodingBootcamp #DevJava #SoftwareEngineer #BTech #CodingInterview #JavaDeveloper

Видео 99℅ of Beginners Fail this Simple Java Math..Can you guess the output? #devjava #facts #coding канала DevDotJava
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять