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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:55:35+00:00 2026-05-30T12:55:35+00:00

Possible Duplicate: What is the difference between a definition and a declaration? I am

  • 0

Possible Duplicate:
What is the difference between a definition and a declaration?

I am confuse about the function declare on head file. does this is same as java, declare function on one file,in that that file has function also has method.
does in C, make the function and method in two different files?
here is a example:

song.h

 typedef struct {
   int lengthInSeconds;
   int yearRecorded;
 } Song;

 Song  make_song    (int seconds, int year);
 void  display_song (Song theSong);

song.c

 #include <stdio.h>
 #include "song.h"

 Song make_song (int seconds, int year)
 {
    Song newSong;

    newSong.lengthInSeconds = seconds;
    newSong.yearRecorded    = year;
    display_song (newSong);

    return newSong;
 }

 void display_song (Song theSong)
 {
    printf ("the song is %i seconds long ", theSong.lengthInSeconds);
    printf ("and was made in %i\n", theSong.yearRecorded);
 }

Can I write those two functions on just one file?

Thanks. I am new to C.

Regards.
Ben.

  • 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-30T12:55:36+00:00Added an answer on May 30, 2026 at 12:55 pm

    Functions in C exist in two forms

    • Declaration: The signature is specified but not the implementation
    • Definition: The implementation and signature are defined

    A declaration is best visualized as a promise of a later function definition. It’s declaring what the function will look like but not telling you what it actually does. It’s common practice to add the declaration of functions shared amongst files in a header.

    // Song.h
    
    // make_song declaration
    Song make_song(int seconds, int year);
    

    Now other files can use make_song by including Song.h. They need to know nothing about it’s implementation just what it’s signature is. The definitions are typically placed in a .c file of the same name as the .h that defines them.

    This is the standard convention for functions shared amongst files but by no means the only way to define functions. It’s possible for functions in C to

    • Only have a definition. If there is a function which is only used within a single .c file there is no reason it needs to be declared in a .h. It can exist wholly within the .c file
    • Only have a declaration. It’s legal, but confusing, to declare a function and never actually give it a definition. The function can’t be called but the code will compile just fine
    • Only have the definition in the .h file. There are lots of linkage caveats here but it is possible to define a function completely within the .h file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is the difference between a definition and a declaration? I am
Possible Duplicate: What is the difference between app.config file and XYZ.settings file? I'm not
Possible Duplicate: Difference between int[] array and int array[] I was sure that this
Possible Duplicate: difference between destructor and garbage collector Recently i asked this question ,
Possible Duplicate: Difference between a Structure and a Union in C I see this
Possible Duplicate: Difference between try-catch syntax for function What is the difference in the
Possible Duplicate: What's the difference between a header file and a library? Can anyone
Possible Duplicate: Difference between pointer variable and reference variable in C++ I saw this
Possible Duplicate: Difference between (function(){})(); and function(){}(); I have seen it a lot by
Possible Duplicate: Difference between WIN32 and other c string I got this code inside

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.