write a program for size of a data type without using
sizeof() operator?

Answer Posted / sunil

This has been solved in parts. I am not sure if there are
any better method merging it.

case 1. User passes a variable as the parameter.
eg: int n;
sizeof(n);

case 2. User passes a data type as the parameter.
eg: sizeof(int)


Solution
case 1: #define GetSize(x) (char*)(&x + 1) - (char*)&x

case 2:#define GetMySize(x) (char*)((x*)10 + 1) - (char*)10

Is This Answer Correct ?    15 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If errno contains a nonzero number, is there an error?

1060


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

1149


The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference

954


Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent

1925


Why calloc is better than malloc?

801


Why pointers are used in c?

774


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

832


Difference between malloc() and calloc() function?

897


Does * p ++ increment p or what it points to?

851


Do array subscripts always start with zero?

1024


Explain the use of fflush() function?

863


What is the use of a conditional inclusion statement in C?

851


Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given

2826


What is a floating point in c?

824


Are enumerations really portable?

803