Results 1 to 4 of 4

Thread: Find the size of a datatype

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Answers
    1

    Find the size of a datatype

    Is there any way to find the size of a datatype without using "sizeof()" operator?


  2. #2
    Contributing Member
    Join Date
    Feb 2007
    Answers
    47

    Re: Find the size of a datatype

    Why to go for another choice if we have sizeof operator??

    Anyways,we can find out like this:

    #define sizeof_type( type ) (size_t)((type*)1000 + 1 )-(size_t)((type*1000)

    ------------
    Neelima


  3. #3
    Junior Member
    Join Date
    Jun 2007
    Answers
    4

    Re: Find the size of a datatype

    Here is a full program as a solution

    #include <iostream>
    #include <conio.h>
    using namespace std;

    template <class T>
    size_t getsize()
    {
    T *p;
    T *q;
    q=p++;
    return reinterpret_cast<size_t>(p) - reinterpret_cast<size_t>(q);
    }

    int main()
    {
    cout<<sizeof(char)<<" "<<getsize<char>()<<endl;
    cout<<sizeof(short)<<" "<<getsize<short>()<<endl;
    cout<<sizeof(int)<<" "<<getsize<int>()<<endl;
    cout<<sizeof(long)<<" "<<getsize<long>()<<endl;
    getchar();

    }


    -Sandeep


  4. #4
    Junior Member
    Join Date
    Jul 2007
    Answers
    1

    Re: Find the size of a datatype

    entadi asalu artham kavatam ledu


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact