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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:51:49+00:00 2026-05-29T22:51:49+00:00

In a simple program that use a function doSomething() to print out a hello,

  • 0

In a simple program that use a function doSomething() to print out a “hello, world”. I only typed a prototype of this function in the main.cpp file and the declaration for this function in another file named do.cpp.

when I compile the program it run properly even though I did not specify which file the declaration of the doSomething() will be.

  • 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-29T22:51:51+00:00Added an answer on May 29, 2026 at 10:51 pm

    There seems to be some confusion in your idea of function declaration and definition.
    The declaration of the function is the prototype of the function.
    For Ex:

    void doSomething();
    

    While, the definition is the body of the function.
    For Ex:

     void doSomething()
     {
     }
    

    Usually, the declaration goes in the header file and the definition in the cpp file.

    The compiler uses the declaration to match the parameters of the function being called, while the linker links the definition to the function being called.

    Compilation is the process where source files are compiled in to object files.
    While during linking all the object files are used by the linker to produce the executable. linker has access to different object files and hence the definition of the function defined in other file.As long as the function name is unique, the linker will happily link to that particular definition, in case linker finds more than two matches then your program breaks the One definition rule and will report multiple definition errors.

    Also, note that the linker needs to use(link) the function definition only if the function is being called, if your program just declares a function, does not provide a definition and never uses(calls) the function there will not be any errors.

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

Sidebar

Related Questions

I have written a simple program that use some classes and procol buffers. These
So I have this Java program that I use to munch through several terabytes
I got a program that has a quite simple 'load up' function that takes
Say I have simple program that emulates a board game with a number of
I have a simple program that creates a thread, loops twenty times and then
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
I need to write a simple program that records all the input from parallel
Consider the following simple C program that read a file into a buffer and
I have a simple python program that I'd like to daemonize. Since the point
I have a simple forms program that I have been fighting with for a

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.