Q:

C Program to calculate the size of the structure to subtract the pointers

0

C Program to calculate the size of the structure to subtract the pointers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
#include <stdlib.h>
typedef struct
{
    int Age;
    float Weight;
} sInfo;
int main()
{
    //create an array of structure;
    sInfo JhonFamilyInfo[2];
    //Create pointer to the structure
    sInfo *psInfo  = NULL;
    int iSizeofStructure = 0;
    //Assign the address of array to the pointer
    psInfo = JhonFamilyInfo;
    // Subtract the pointer
    iSizeofStructure = (char*)(psInfo + 1) - (char*)(psInfo);
    printf("Size of structure  =  %d\n\n",iSizeofStructure);
    
    return 0;
}

Output:

Size of structure =  8

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Program to increment a pointer in C... >>
<< void pointer in C...