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
  • 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-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

Ask A Question

Stats

  • Questions 535k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The right way is set JFrame.setDefaultCloseOperation to DO_NOTHING_ON_CLOSE when the… May 17, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer Have you had a look at the documentation yet? It… May 17, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer You should create an IceUserObject and use it as user… May 17, 2026 at 12:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I come from Java background, where we have data structures with interfaces that if
I have learnt C++ for a while and still didn't come across good book
I'm new to Python (I have been programming in Java for multiple years now
I just about to learn Java programming. I already have jdk on my computer.
While doing variadic template programming in C++11 on GCC, once in a while I
I am working with WCF RIA services and have come across a sample using
I've been programming with Java for Android quite some while now. Since performance is
Even after years of programming, I'm ashamed to say that I've never really fully
I have an interesting problem here I've been trying to solve for the last
I've been thinking about this object oriented design question for a while now and

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.