Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:03:39+00:00 2026-06-12T02:03:39+00:00

I have stumbled upon a piece of code that generates some interesting results while

  • 0

I have stumbled upon a piece of code that generates some interesting results while debugging someone else’s program.

I have created a small program to illustrate this behavior:

#include <stdio.h>

int main()
{
        char* word = "foobar"; int i, iterator = 0;
        for (i = 0; i < 6; i++ && iterator++)
          printf("%c", word[iterator]);
        return 0;
}

I know that this is not the right way to print a string. This is for demonstration purpose only.

Here I expected the output to be “foobar”, obviously, but instead it is “ffooba”. Basically it reads the first character twice, as if the first time iterator++ is executed nothing happens.

Can anyone explain why this happens?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:03:40+00:00Added an answer on June 12, 2026 at 2:03 am

    The thing is iterator++ actually isn’t executed the first time. The ++ operator returns the current value of a variable and then increments it, so the first time through, i++ will be equal to 0. && short-circuits, so iterator++ is not executed the first time.

    To fix this, you could use the comma operator which unconditionally evaluates both, rather than the short-circuiting &&.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am debugging some old ASP code and have stumbled upon the following error:
I have stumbled upon an interesting problem/bug that I eventually solved, but the solution
I stumbled upon this piece of code while reading about DES encryption. I wonder
Just stumbled upon propertyGrid and its awesome! However, i have one task that i
I'm hoping someone happens to have stumbled upon the following issue before. My Java
While looking for something totally different the other day, I have stumbled upon two
I have been going over rails scheduling tasks options and stumbled upon this piece
Some of you might have stumbled upon this cute article - http://igoro.com/archive/quicksort-killer/ \ What
Greets, I'm currently working on a website and have stumbled upon some layout difficulties.
I have stumbled upon this code var Actors = { init: function(config){ this.config =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.