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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:59:49+00:00 2026-05-28T00:59:49+00:00

I’m working through K & R to learn programming. Going well so far, but

  • 0

I’m working through K & R to learn programming. Going well so far, but I’m unclear about the role of a line of code from section 1.8 (functions).

In section 1.8, the authors show you how to create a function to raise one integer to the power of another integer.

I’ve pasted the code below, as it was written in the book. Everything outputs fine. But I don’t know why they’ve included this line at the top:

int power(int m, int n);

The book doesn’t mention it, apart from saying that the program will raise integer m to the power n. If I remove the line from the code, the program still outputs as it should.

If I understand this correctly, the line

int power(int base, int n)

creates the function, and the braces underneath define the function. Then the braces under main call the function to output the chart.

So all that seems to make sense. But I don’t see what the very top line does.

It could be extraneous, but it seems far more likely that I’m missing something. Can anyone enlighten me as to why that line is there?

#include <stdio.h>

int power(int m, int n);

/* test power function */
main()
{
int i;

    for (i = 0; i < 10; ++i)
        printf("%d %d %d\n", i, power(2,i), power(-3, i));
    return 0;
}

/* power: raise base to n-th power; n >= 0 */

int power(int base, int n)
{
    int i, p;

    p = 1;
    for (i = 1; i <= n; ++i)
        p = p * base;
    return p;
}
  • 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-28T00:59:50+00:00Added an answer on May 28, 2026 at 12:59 am

    The first line is the declaration of the function. The block of code at the bottom is the definition of the function.

    Starting with the 1999 version of the ISO C standard, it’s illegal (a constraint violation) to call a function without a visible declaration; the declaration must precede the call.

    For a simple program like this one, you could just write the full definition of power() before the definition of main() (since a definition also provides a declaration), but for more complex cases (such as recursive calls) you often need to provide a separate declaration.

    For larger programs, it’s common to collect all the function declarations in a header file (foo.h, for example), and the corresponding definitions in a source file (foo.c, for example). A #include "foo.h" directive is used to make the declarations visible in other files. You’ll see that kind of thing later in the book.

    (In the 1990 and earlier versions of C, which is what K&R2 covers, there are cases where you can call a function without a visible declaration — but it’s still a very good idea to provide explicit declarations anyway.)

    Incidentally, the declaration of the main program should really be int main(void) rather than just main().

    Terminology: a “prototype” is a function declaration that specifies the types of the parameters.

    int power(int base, int n);    /* a declaration that's also a prototype */
    int power(int, int);           /* likewise */
    int power();                   /* a declaration but not a prototype */
    

    (Parameter names are required in a definition, but optional in a standalone declaration.)

    As a special case, a prototype for a function with no parameters uses (void), since empty parentheses already mean a non-prototype declaration. So int main(void) is a prototype, but int main() isn’t.

    Non-prototype declarations are “obsolescent”, meaning that they could in theory be removed from a future language standard. But they’ve been obsolescent since 1989, and even in the new 2011 ISO C standard the committee hasn’t seen fit to remove them.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put

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.