struct ptr
{
int a;
char b;
int *p;
}abc;
what is d sizeof structure without using "sizeof" operator??
Answer Posted / vadivel t
Hi All,
The size of any data type is depends on the compiler
(including struct, union and enum). But the question does
not mean, "what is the size of the given structure".
It actually means,
Find the size of the structure without using sizeof()
operator.
The Answer, irrespective of compiler would be,
Output of the following code.
-First printf gives the size of the structure, wthout using
size of operator.
-U can cross check the ans using sizeof() operator in the
second printf().
#include<stdio.h>
struct name
{
int a;
char b;
int *p;
}abc;
main()
{
struct name *ptr, *ptr1;
ptr = &abc;
ptr1 = ptr + 1;
printf("WITHOUT USING sizeof() OPERATOR: %d \n",((char *)
ptr1 - (char *)ptr));
printf("USING sizeof() OPERATOR: %d \n", sizeof(abc));
getch();
}
Is This Answer Correct ? | 13 Yes | 0 No |
Post New Answer View All Answers
What is the purpose of macro in C language?
Why does everyone say not to use scanf? What should I use instead?
What is c language and why we use it?
What is the difference between exit() and _exit() function in c?
How can a program be made to print the line number where an error occurs?
What is sizeof array in c?
What are the functions to open and close file in c language?
Explain what is the difference between a free-standing and a hosted environment?
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
int i=10; printf("%d %d %d", i, i=20, i);
how to print the character with maximum occurence and print that number of occurence too in a string given ?
What is an expression?
How can I access an I o board directly?
What is the difference between class and object in c?
Explain Basic concepts of C language?