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

write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

1777


What is a wrapper function in c?

573


What functions are used for dynamic memory allocation in c language?

592


Explain what is page thrashing?

603


What is structure padding and packing in c?

608






Do you know null pointer?

596


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

615


4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.

1718


What is formal argument?

637


Disadvantages of C language.

647


How are pointers declared in c?

590


how many errors in c explain deply

1623


What is c language in simple words?

584


Can a void pointer point to a function?

563


How can I generate floating-point random numbers?

596