C Program to calculate the size of the structure to subtract the pointers
#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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
Size of structure = 8
need an explanation for this answer? contact us directly to get an explanation for this answer