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


Please Help Members By Posting Answers For Below Questions

What is the purpose of macro in C language?

851


Why does everyone say not to use scanf? What should I use instead?

1074


What is c language and why we use it?

802


What is the difference between exit() and _exit() function in c?

830


How can a program be made to print the line number where an error occurs?

870


What is sizeof array in c?

770


What are the functions to open and close file in c language?

944


Explain what is the difference between a free-standing and a hosted environment?

902


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

858


int i=10; printf("%d %d %d", i, i=20, i);

1291


how to print the character with maximum occurence and print that number of occurence too in a string given ?

2243


What is an expression?

836


How can I access an I o board directly?

824


What is the difference between class and object in c?

813


Explain Basic concepts of C language?

826