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

  • Home
  • SEARCH
  • 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 1024931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:51:04+00:00 2026-05-16T11:51:04+00:00

While programming I have come to an unusual error. When I initialize an integer

  • 0

While programming I have come to an unusual error. When I initialize an integer in a loop, sometimes it says that the expression is not valid, but at times it accepts it.
This is my code which gives error:

int pow(int x,int n);
int main()
{
    int x,n,result;
    printf("Enter a number:\n");
    scanf("%d",&x);
    printf("Enter its power:\n");
    scanf("%d",&n);
    result=pow(x,n);
    printf("Result is %d\n",result);
    getch();
    return 0;
}
int pow(int x,int n)
{   
    for(int i=1;i<n;i++)   //<-- here it says that declaration syntax error
    x=x*i;
    return x;
}

While when i change it like this :

int pow(int x,int n)
{   
    int i;
    for(i=1;i<n;i++)  
    x=x*i;
    return x;
}
  • 1 1 Answer
  • 1 View
  • 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-16T11:51:05+00:00Added an answer on May 16, 2026 at 11:51 am

    C89 and earlier versions only support declaration statements at the head of a block (IOW, the only thing that can appear between an opening { and a declaration is another declaration):

    /* C89 and earlier */
    int main(void)
    {
      int x;                      /* this is legal */
      ...
      for (x = 0; x < 10; x++)
      {
        int i;                    /* so is this */
        printf("x = %d\n", x);
        int j = 2*x;              /* ILLEGAL */
      }
      int y;                      /* ILLEGAL */
      ...
    }
    

    With C99, declaration statements can appear pretty much anywhere, including control expressions (with the caveat that something must be declared before it is used):

    // C99 and later, C++
    int main(void)
    {
      int x;                       // same as before
      ...
      for (int i = 0; i < 10; i++) // supported as of C99
      {
        printf("i = %d\n", i);
        int j = 2 * i;             // supported as of C99
      }
      int y;                       // supported as of C99
    }
    

    Turbo C predates the C99 standard, so if you want to write code like in the second example, you will need to use a more up-to-date compiler.

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

Sidebar

Related Questions

What specific techniques have you found to learn keyboard shortcuts while programming? I don't
I was just wondering while programming. I have got a rootViewController which creates an
I have been programming in Delphi for a while, but I never ran across
Total n00b to C# and events although I have been programming for a while.
I have been researching OpenGL programming on Mac OS X. While a fair amount
While I'm familiar with concurrent programming concepts such as mutexes and semaphores, I have
i've been programming for a while, but have never had a formal computer science
While programming, I often come across the following scenario (described in code). I define
I come from Java background, where we have data structures with interfaces that if
My searches have come up blank, or I am just not understand the results

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.