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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:48:58+00:00 2026-05-24T03:48:58+00:00

When does memory get allocated to a data type, class and function? At the

  • 0

When does memory get allocated to a data type, class and function? At the time of declaration or at the time of definition?

Also is there a way to know the sizeof function?

  • 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-24T03:48:58+00:00Added an answer on May 24, 2026 at 3:48 am

    Size of different program elements in C++

    When does memory get allocated to a data type, class and function? At the time of declaration or at the time of definition?

    A data type is just an abstract notion understood by the compiler. When a variable of that type is needed, memory must be allocated. The:

    • amount of memory – which is available at compile time using the sizeof operator (it’s not a function) – is determined by the compiler: for inbuilt types it’s fixed based on their binary representation, for user-defined types it’s basically a "recursive" sum of the data member’s individual sizes adjusted for alignment/packing)

    • An actual address may be determined at:

      • compile time (typically global and static variables) [further details in comments]
      • at run-time (for heap-allocated variables),
      • in a hybrid run-time-stack-frame-relative way for local variables
      • at load-time or in a base-address-relative way (for global/extern/static symbols in dynamically loaded libraries).

    Classes are just user-defined data types, and follow these same rules, though for classes it’s possible for the size to be unknown if a declaration has been seen by the compiler, but the definition is further into the source code: until the compiler sees the definition it can’t calculate the size of the object, and you can make very limited use of the class identifier – creating pointers and references that will point to an instance, but not actual variables of that type.

    Also is there any way to know the sizeof function?

    Again – it’s an operator which basically injects the compile-time constant size value that the compiler’s calculated. As such, there is no sizeof function in any machine-code object the compiler produces.

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

Sidebar

Related Questions

Does anyone know what advantages (memory/speed) there are by using a class generated by
Possible Duplicate: Does this type of memory get allocated on the heap or the
When we create an object of a class what does it memory map look
As far as I know, memcached runs in-memory and does not have a persistent
I know that class variables are declared in memory (as opposed to on the
Does the MEMORY storage engine of MySQL ever write to disk the database contents?
CLR profiler does not seem to work with the Silverlight CLR. Does another memory
Regarding: Delphi, VirtualStringTree - classes (objects) instead of records Does the memory increases or
Does gcc have memory alignment pragma, akin #pragma vector aligned in Intel compiler? I
Does Java 6 consume more memory than you expect for largish applications? I have

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.