size of a datatype without using sizeof

后端 未结 21 1783
慢半拍i
慢半拍i 2020-12-01 02:34

I have a data type, say X, and I want to know its size without declaring a variable or pointer of that type and of course without using sizeof oper

相关标签:
21条回答
  • 2020-12-01 03:03
    # include<stdio.h>
    
    struct node
    {
      int a;
      char c;
    };
    
    void main()
    {
       struct node*ptr;
       ptr=(struct node*)0;
       printf("%d",++ptr);
    }
    
    0 讨论(0)
  • 2020-12-01 03:03
    #include <bits/stdc++.h> 
    
    using namespace std; 
    
    int main() 
    { 
    
        // take any datatype hear 
        char *a = 0; // output: 1
    
        int  *b = 0;  // output: 4
    
        long *c = 0; // output: 8
    
        a++;
    
        b++;
    
        c++;
    
        printf("%d",a);
    
        printf("%d",b);
    
        printf("%d",c);
    
        return 0; 
    }
    
    0 讨论(0)
  • 2020-12-01 03:04

    Well, I am an amateur..but I tried out this problem and I got the right answer without using sizeof. Hope this helps.. I am trying to find the size of an integer.

    int *a,*s, v=10;
    
    a=&v;
    
    s=a;
    
    a++;
    
    int intsize=(int)a-(int)s;
    
    printf("%d",intsize);
    
    0 讨论(0)
提交回复
热议问题