GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 53 of 110    Print  
How to find the size of data without using the sizeof() operator?

  
Total Answers and Comments: 1 Last Update: September 18, 2007     Asked by: kaliswaranbsc 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: baseersd
 
Here is the code for finding the size of data types without using sizeof()



#include<stdio.h>
#define size_of(data) ( (char *)(&data +1) - (char *)(&data))
int main()
{
    int INT;
    char CHAR;
    float FLOAT;
    double DOUBLE;
    printf("Sizeof int ::%dn",size_of(INT));
    printf("Sizeof char ::%dn",size_of(CHAR));
    printf("Sizeof float ::%dn",size_of(FLOAT));
    printf("Sizeof double ::%dn",size_of(DOUBLE));
    
    system("pause");
    return 0;
        
}




Above answer was rated as good by the following members:
aks3937
September 18, 2007 04:52:05   #1  
baseersd Member Since: June 2007   Contribution: 34    

RE: How to find the size of data without using the siz...
Here is the code for finding the size of data types without using sizeof()



#include<stdio.h>
#define size_of(data) ( (char *)(&data +1) - (char *)(&data))
int main()
{
int INT;
char CHAR;
float FLOAT;
double DOUBLE;
printf("Sizeof int :: dn" size_of(INT));
printf("Sizeof char :: dn" size_of(CHAR));
printf("Sizeof float :: dn" size_of(FLOAT));
printf("Sizeof double :: dn" size_of(DOUBLE));

system("pause");
return 0;

}



 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

Q1. write a program to find a given number is armstrong number or not ?Q2write a program which accepts a filename as a command line argument and reverse the contents of the file(i.e first character becomes the last character of the file and so on ?Q3 how can i call a function given its name as a string ?Q4 How to swap low-order byte and high order byte in an integer without using temporary variable?Q5 If we develop a project in C, then how can we create an .exe file of it?Q6 how to print 1 to 100
please let me know the answers to my email address as i having the interview in TCS so please please please please let me know  
Read Answers (18) | Asked by : M.srilatha

What is the output of the following program#includevoid main(){printf("%d%d",sizeof('a'),sizeof("a"));

Latest Answer : #include#includevoid main(){ int a,i;clrscr();printf( " enter the number");scanf("%d",&a);for(i=a;i

1) If either operand of an arithmetic operator is unsigned long, the other operand is promoted to unsigned long. 2) If either operand of an arithmetic operator is unsigned int, the other operand 
Latest Answer : Here we cant say the default promotion without knowing the other operand.But if two operands are of different datatypes and the arithmetic operation is performed on these operands the compiler allocates the memory  of higher datatype for the resulting ...
Read Answers (1) | Asked by : Ashish

int *ptr = (int *)malloc(100*(sizeof(int)));ptr++;free(ptr); 
Latest Answer : it will allocate 200 bytes of memory and returns pointer to the first location...correct me if iam wrongregardsumesh ...

View Question | Asked by : Pankaj sharma`

Latest Answer : #include#includevoid main(){int x,y,z;clrscr();printf("enter the number");scanf("%d",&x);while(x>0){y=x%10;printf("%d",y);x=x/10;}getch();} ...
Read Answers (1) | Asked by : mcamuthu

We have a 2 arrays e.g. arr1[]={2,3,4,4,5,6,7} , arr2[]={1,2,2,4,6,8,8} . Assuming that both the arrays are sorted , if we want to write a program to find common numbers present in both arrays , how do we do that ? Note that nested for loop has a complexity of n2 , hence avoid nested for loop.
View Question | Asked by : Ajay Kanse

Latest Answer : Here is the code for finding the size of data types without using sizeof() #include#define size_of(data) ( (char *)(&data +1) - (char *)(&data))int main(){    int INT;    char CHAR;    ...



 Sponsored Links

 
Related Articles

Breaking up XML into Relational Data

Breaking up XML into Relational Data While the preceding example shows how to construct an XML representation over relational data the example in this section illustrates how you can shred XML data back into relational data This reverse operation can be useful if your application works with relation
 

Querying Data with Oracle XQuery

Querying Data with Oracle XQuery Starting with Oracle Database 10g Release 2 you can take advantage of a full featured native XQuery engine integrated with the database With Oracle XQuery you can accomplish various tasks involved in developing PHP Oracle XML applications operating on any kind of dat
 

Retrieving XML Data

Retrieving XML DataTo retrieve XML data from an XMLType table you can use a SELECT SQL statement just as you would if you had to query a relational table For example to select the employee with the id set to 100 from the employees XMLType table discussed in the preceding section you might issue the
 

Using XMLType for Handling XML Data in the Database

Using XMLType for Handling XML Data in the Database Being an object type XMLType can not only be used to store XML data in the database but also to operate on that data via its built in methods Regardless of the storage model you choose XMLType provides a set of XML specific methods to operate on XM
 

Using Oracle Database for Storing, Modifying, and Retrieving XML Data

Using Oracle Database for Storing Modifying and Retrieving XML Data With Oracle XML DB you have various XML storage and XML processing options allowing you to achieve the required level of performance and scalability One of the most interesting things about Oracle XML DB is that it allows you to per
 

ODP.NET - Techniques to Improve Performance while Retrieving Data

ODP NET Techniques to Improve Performance while Retrieving Data Performance tuning is a great subject in Oracle Volumes of books would not be enough to cover every aspect of performance tuning in Oracle However in this section we will only discuss the fundamental performance techniques while working
 

ODP.NET - Populating a Dataset with a Single Data Table

ODP NET Populating a Dataset with a Single Data Table A dataset is simply a group of data tables These data tables can be identified with their own unique names within a dataset You can also add relations between data tables available in a dataset mosgoogle The following code gives you the details o
 

ODP.NET - Retrieving Typed Data

ODP NET Retrieving Typed Data While retrieving values from OracleDataReader we can extract information available in individual columns of a particular row either by using column ordinal position values or column names mosgoogle Retrieving Typed Data Using Ordinals ODP NET provides data specific enum
 

ODP.NET - Retrieving Data Using OracleDataReader

ODP NET Retrieving Data Using OracleDataReader OracleDataReader is simply a read only and forward only result set It works only if the database connection is open and it makes sure that the connection is open while you are retrieving data As the data that it retrieves is read only it is a bit faster
 

ODP.NET - Fundamental ODP.NET Classes to Retrieve Data

ODP NET Fundamental ODP NET Classes to Retrieve Data To retrieve data from an Oracle database using ODP NET we need to work with a few of the ODP NET classes At this point we will discuss the most fundamental classes available in ODP NET for retrieving data mosgoogle The following is the list of fun
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape