Write a program to find the size of following structure without using size of operator
struct ABC
{
int a;
float b;
char c;
};
Hai Viewer, confused?? Hmm.. calculating the size of a datatype without using sizeof() operator seems to be weird. But pointers will help you to solve this problem. First u have to initialize a null pointer on intended datatype .You know that in 'structure ' separate memory will be allocated to each element. So, on incrementing that pointer variable, the value of that pointer will be incremented by size of that structure . That is our Goal..!!!! :)
Since we have initialized pointer with 0 we simply need to print the current pointer value..!!
solution
#include<stdio.h>
struct ABC
{
int a;
float b;
char c;
};
int main()
{
struct ABC *ptr=(struct ABC *)0;
ptr++;
printf("%d",ptr);
getch();
return 1;
}
I hope this code was useful for u!!
Have a better program for ths prblm??
Feel free to comment it here..!! :):):)
struct ABC
{
int a;
float b;
char c;
};
Hai Viewer, confused?? Hmm.. calculating the size of a datatype without using sizeof() operator seems to be weird. But pointers will help you to solve this problem. First u have to initialize a null pointer on intended datatype .You know that in 'structure ' separate memory will be allocated to each element. So, on incrementing that pointer variable, the value of that pointer will be incremented by size of that structure . That is our Goal..!!!! :)
Since we have initialized pointer with 0 we simply need to print the current pointer value..!!
solution
#include<stdio.h>
struct ABC
{
int a;
float b;
char c;
};
int main()
{
struct ABC *ptr=(struct ABC *)0;
ptr++;
printf("%d",ptr);
getch();
return 1;
}
I hope this code was useful for u!!
Have a better program for ths prblm??
Feel free to comment it here..!! :):):)