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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:41:25+00:00 2026-05-22T00:41:25+00:00

I have a very simple bit of code that won’t work, and have no

  • 0

I have a very simple bit of code that won’t work, and have no idea why

The following:

int flag = 0;
if (flag == 0)
{
    flag = 1;
}

Will not compile. It is already a quite complex program, and I am able to do other actions within the program with no problems at all, yet for some reason I can’t reference a variable I have just created. The variable name is unique, and the application is a Windows app including windows.h. It is written in C, and up until now I have not attempted to create my own variables.

I can’t publish the full code here, least of all because there’s pages of it, but can anyone speculate as to why it can’t compile? I am using Visual C++ and have the following errors:

syntax error : missing ';' before 'type' (this applies to line 1)
'flag' : undeclared identifier (line 2)
'flag' : undeclared identifier (line 4)

I have tried using bool as well, with ‘true’ and ‘false’ in place. I am relatively new to C++. Note that the code compiles fine without it here at all. It comes immediately after a previous action within a larger ‘if’ statement, of which this is a part. I have successfully added other nested if statements in the exact same place as this. Taking it outside the if statement entirely makes no difference. Putting it all right at the top of my main.c file, just after the #includes, makes no difference. Removing it completely means the program compiles absolutely fine. The problem seems to lie with defining the variable.

  • 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-22T00:41:26+00:00Added an answer on May 22, 2026 at 12:41 am

    I assume you compile it to C language. You need to declare the variable at the beginning of the block:

    // beginning of block
    int flag=0;
    //Some code
    if (flag == 0)
    {
        flag = 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple bit of code that is supposed to capture the
I have a very simple bit of script that changes the status of an
I have a very simple Java RMI Server that looks like the following: import
So say I have the following very simple macro, along with a bit of
i have very simple problem. I need to create model, that represent element of
I have a very simple ASP.Net page that acts as a front end for
I have some very simple code to generate an assembly and invoke a method
I'm implementing a very simple audio-only RTMP server. I have my client code like
I have very simple question but the answer is still not clear. If i
I have very simple select like this: SELECT * FROM table WHERE column1 IN

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.