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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:58:27+00:00 2026-06-12T14:58:27+00:00

I am learning C, and after starting out learning C++ as my first compiled

  • 0

I am learning C, and after starting out learning C++ as my first compiled language, I decided to “go back to basics” and learn C.

There are two questions that I have concerning the ways each language deals with functions.

Firstly, why does C “not care” about the scope that functions are defined in, whereas C++ does?

For example,

int main()
{
    donothing();
    return 0;
}

void donothing() { }

the above will not compile in a C++ compiler, whereas it will compile in a C compiler. Why is this? Isn’t C++ mostly just an extension on C, and should be mostly “backward compatible”?

Secondly, the book that I found (Link to pdf) does not seem to state a return type for the main function. I check around and found other books and websites and these also commonly do not specify return types for the main function. If I try to compile a program that does not specify a return type for main, it compiles fine (although with some warnings) in a C compiler, but it doesn’t compile in a C++ compiler. Again, why is that? Is it better style to always specify the return type as an integer rather than leaving it out?

Thanks for any help, and just as a side note, if anyone can suggest a better book that I should buy that would be great!

  • 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-06-12T14:58:29+00:00Added an answer on June 12, 2026 at 2:58 pm

    Firstly, why does C “not care” about the scope that functions are defined in, whereas C++ does?

    Actually, C does care. It’s just that C89 allows implicitly declared functions and infers its return type as int and its parameters from usage. C99 no longer allows this.

    So in your example it’s as if you had declared a prototype as

    int dosomething();
    

    The same goes for implicit return types: missing return types are inferred as int in C89 but not C99. Compiling your code with gcc -std=c99 -pedantic-errors yields something similar to the following:

    main.c: In function 'main':
    main.c:2:5: error: implicit declaration of function 'donothing' [-Wimplicit-function-declaration]
    main.c: At top level:
    main.c:5:6: error: conflicting types for 'donothing'
    main.c:2:5: note: previous implicit declaration of 'donothing' was her
    

    For the record, here’s the code I’ve used:

    int main() {
        donothing();
        return 0;
    }
    void donothing() { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting to learn Java a little after long time. And learning Netbeans
After learning how to correctly unset a node , I noticed that using PHP's
After learning about source control the first thing I did is do a project
I am just starting learning about Linq. I wrote some examples but there is
I'm starting out with Lift and been reading a few tutorials and books that
After learning about how to print out debug messages using Visual Studio's Tracepoint feature,
After learning that JADE does not support Mobile Agent concept but supports only traditional
G'day all, After learning on here that the Java console doesn't support keyboard input
After learning the basics of CSS and jQuery, I'd like to set up a
I'm a Delphi, Ruby, and Javascript programmer that is finally learning C - starting

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.