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 708435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:23:26+00:00 2026-05-14T04:23:26+00:00

This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =

  • 0

This part of my code works fine:

#include <stdio.h>

int main(){
    //char somestring[3] = "abc";
    int i, j; 
    int count = 5;

    for((i=0) && (j=0); count > 0; i++ && j++){
        printf("i = %d  and j = %d\n", i, j);
        count--;
    }

    return 0;
}

The output as expected:

i : 0 and j : 0
i : 1 and j : 1
i : 2 and j : 2
i : 3 and j : 3
i : 4 and j : 4

Things get weird when I uncomment the char string declaration on the first line of the function body.

#include <stdio.h>

int main(){
    char somestring[3] = "abc";
    ...
}

The output:

i : 0 and j : 4195392
i : 1 and j : 4195393
i : 2 and j : 4195394
i : 3 and j : 4195395
i : 4 and j : 4195396

What’s the logic behind this? I’m using gcc 4.4.1 on Ubuntu 9.10.

  • 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-05-14T04:23:27+00:00Added an answer on May 14, 2026 at 4:23 am

    j never gets initialised, because of the short-circuiting behaviour of &&. Since (i=0) evaluates to false, (j=0) never gets executed, and hence j gets a random value. In the first example, that just happens to be zero.

    You should say i=0, j=0 to achieve what you want.

    The i++ && j++ has the same problem; it should be i++, j++.

    Also, this:

    char somestring[3] = "abc";
    

    is reserving one too few bytes, because of the trailing NUL character in the string – you need four bytes. But if you’re not going to modify the string, you don’t need to specify the number of bytes – you can simply say this:

    char *somestring = "abc";
    

    instead.

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

Sidebar

Related Questions

Note : The code in this question is part of deSleeper if you want
It's a part of larger code base, which forces -Werror on gcc. This warning
Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of
I'm trying to reteach myself some long forgotten math skills. This is part of
This is a part algorithm-logic question (how to do it), part implementation question (how
How can I extract the part of this stream (the one named BLABLABLA) from
I'm working on a document application and part of this application I've to add
I'm writing an app to help facilitate some research, and part of this involves
I'm working on a internal web based tool for my company. Part of this
This is actually a two part question. First,does the HttpContext.Current correspond to the current

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.