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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:28:25+00:00 2026-05-20T07:28:25+00:00

I am new to C and I experience some confusion between the declaration and

  • 0

I am new to C and I experience some confusion between the declaration and definition of a variable. Another thing I would like to know is if the following is true:

“Declaration appears many times and definition comes once.”

Also:

int x; 

Is this a declaration only? Since memory is allocated for x then why isn’t this a definition instead of a declaration?

  • 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-20T07:28:26+00:00Added an answer on May 20, 2026 at 7:28 am

    This isn’t something you see too much in C, but it works like this:

    In a header file, you can have a line like this:

    extern int x; //declaration
    

    Because of the extern modifier, this tells the compiler that there is an int named x somewhere. The compiler doesn’t allocate space for it – it just adds int x to the list of variables you can use. It’ll only allocate space for x when it sees a line like this:

    int x; //definition
    

    You can see that because only the int x; line changes your executable, you can have as many extern int x; lines as you feel like. As long as there’s only int x; line, everything will work like you want it to – having multiple declarations doesn’t change a thing.

    A better example comes from C++ (sorry if this is a C-only question – this applies to structs as well, but I don’t know the syntax off the top of my head):

    class Pineapple; //declaration
    
    Pineapple* ptr;  //this works
    Pineapple pine;  //this DOES NOT work
    

    This declaration tells the compiler that there’s a class called “Pineapple”. It doesn’t tell us anything about the class (how big it is, what its members are). We can use pointers to Pineapples now, but we can’t yet have instances – we don’t know what makes up a Pineapple, so we don’t know how much space an instance takes up.

    class Pineapple
    {
    public:
        int ounces;
        char* name;
    }; //definition
    
    Pineapple* ptr;   //still works
    Pineapple pine;   //this works now too!
    //we can even get at member variables, 'cause we know what they are now:
    pine.ounces = 17;
    

    After a definition, we know everything about the class, so we can have instances, too. And like the C example, you can have multiple declarations, but only one definition.

    Hope this helps!

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

Sidebar

Related Questions

I'm kind of new to WPF although I have some experience in Forms, and
Hey, i have some experience with MVC. but I'm new to rails. I'm using
I am a bit new with android but I have some java experience. So
I'm new to Java, but have some OOP experience with ActionScript 3, so I'm
I'm pretty much new to Objective C but I've had some experience in Visual
Kinda new to Silverlight and have some experience with WPF but I'm doing a
I'm pretty new to Android but I have some experience (and a bit rusty
I am new to computer programming and have some experience programming with python. I
As the topic says I'm very new to c++, but I have some experience
I'm new to the C++ world, but I have some experience with C and

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.