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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:27:35+00:00 2026-05-27T06:27:35+00:00

In the C++ language, is it legal to put function prototypes inside of main

  • 0

In the C++ language, is it legal to put function prototypes inside of main or another function? Is this bad practice? Why would someone put prototypes inside of main?

  • 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-27T06:27:35+00:00Added an answer on May 27, 2026 at 6:27 am

    Yes, it is legal – there is no doubt about that. It is usually not advisable, though.

    One reason that it isn’t advisable is that the function is then only available (as a result of that declaration) in that particular function; other functions in the same file cannot make use of that declaration (but the other functions might contain their own declaration of the function – but then you’re repeating yourself, which isn’t a good idea).

    Additionally, you lose the primary benefit of cross-checking. The best way to do it is:

    • If the function is defined in the same source file (and not used outside the source file), then limit its scope to the file (static or the anonymous namespace, or in the appropriate other namespace), and ensure it is either defined or declared before it is used.
    • If the function is defined in a different source file, there should be a header that declares the function. Include the header in both the file that defines the function (to ensure that the declaration in the header is consistent with the definition) and in the files that use the function.

    This way, if you need to change the function declaration, you have fewer places to track down. If you have the function declared in multiple places, you have to change all the declarations at once. Of course, for a radical enough change (extra arguments, or fewer arguments) you will have to modify the calls to the function; for other changes (such as adding a const qualifier to an argument, or changing from pass-by-value to pass-by-reference), you may not need to change anything in the source; a simple recompile may be sufficient.

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

Sidebar

Related Questions

Language: asp This is sample of my code: str = www.example.com/gotobuy.aspx?id=1234 key_word = .obuy.
This probably is one of the easiest question ever in C programming language... I
In all the languages that I understand this is not possible but someone was
I have introduced a Rhino-based scripting language. In this language, by its nature of
What language feature or outside-the-box hack can I use to accomplish function inlining in
In many languages, assignments are legal in conditions. I never understood the reason behind
Language used: C# Theory: I want to create a file with the flag FileOptions.DeleteOnClose
Language = C# .NET version = 3.5 When my code performs syntax highlighting the
Language Visual Basic 6. I want to know if there is an open source
language c#, winform how do i create a modal window or such a thing

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.