Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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

Answer / desh deepak

void main()
{
char *Ptr1,*Ptr2;
float fl;
ptr1 = &fl;
ptr2 = (&fl+1);

printf("%u",ptr2-ptr1);
}

Is This Answer Correct ?    18 Yes 18 No

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

Answer / lalit kumar

#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
int main()
{
int a;
printf("%u\n",(int)(&a+1)-(int)(&a));
getch();
return 0;
}

Is This Answer Correct ?    1 Yes 1 No

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

Answer / fanish

#include <stdio.h>
int main(){
printf("%d\n",((int*)0 + 1));
}

We can replace int with any other type
(Built-in/user-defined ) to get the size.

Is This Answer Correct ?    1 Yes 1 No

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

Answer / core_coder

#include <stdio.h>

struct node {
int x;
int y;
};

unsigned int find_size ( void* p1, void* p2 )
{
return ( (char*)p2 - (char*)p1 );
}

int main ( int argc, char* argv [] )
{
struct node data_node;
int x = 0;

printf ( "\n The size :%d",
find_size ( (void*) &data_node,
(void*) ( &data_node +
1 ) ) );
printf ( "\n The size :%d", find_size ( (void*) &x,
(void*) ( &x + 1 ) ) );
}

this will work for any data type

Is This Answer Correct ?    1 Yes 1 No

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

Answer / p sahana upadhya

#include<stdio.h>
#include<math.h>
main()
{
float size;
printf("The Size of Integer Data Type is %d
Bytes\n",(sizeof(int)));
size=pow(2,(sizeof(int)*8));
printf("The Range of Integer Data Type is -%.0f to
%.0f\n\n",(size/2),((size/2)-1));

printf("The Size of Long Integer Data Type is %d
Bytes\n",(sizeof(long int)));
size=pow(2,(sizeof(long int)*8));
printf("The Range of Long Integer Data Type is -%.0f
to %.0f\n\n",(size/2),((size/2)-1));

printf("The Size of Unsigned Long Data Type is %d
Bytes\n",(sizeof(long int)));
size=pow(2,(sizeof(long int)*8));
printf("The Range of Unsigned Long Data Type is 0 to
%.0f\n\n",size);

printf("The Size of Float Data Type is %d Bytes\n",
(sizeof(float)));
size=pow(2,(sizeof(float)*8));
printf("The Range of Float Data Type is -%.0f to
%.0f\n\n",(size/2),((size/2)-1));

printf("The Size of Double Data Type is %d Bytes\n",
(sizeof(double)));
size=pow(2,(sizeof(double)*8));
printf("The Range of Double Data Type is -%.0f to
%.0f\n\n",(size/2),((size/2)-1));

printf("The Size of Long Double Data Type is %d
Bytes\n",(sizeof(long double)));
size=pow(2,(sizeof(long double)*8));
printf("The Range of Long Double Data Type is -%.0f
to %.0f\n\n",(size/2),((size/2)-1));

printf("The Size of Char Data Type is %d Bytes\n",
(sizeof(char)));
size=pow(2,(sizeof(char)*8));
printf("The Range of Character Data Type is -%.0f to
%.0f\n\n",(size/2),((size/2)-1));

printf("The Size of Unsigned Char Data Type is %d
Bytes\n",(sizeof(char)));
size=pow(2,(sizeof(char)*8));
printf("The Range of Unsigned Char Data Type is 0 to
%.0f\n\n",size);

getch();
return 0;
}

This program may seems long, but it definitely works!!!!!

Is This Answer Correct ?    3 Yes 3 No

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

Answer / neel patwa

//Nice way to find size of any data type...
#include<iostream.h>
void main(){

int *p=0;
p++;
cout<<"\nSize of int="<<(int)p;
}
Note:U can replace int by other datatpe,
to find size of any data type..

Is This Answer Correct ?    0 Yes 0 No

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

Answer / tishu

#include<stdio.h>
void main()
{
long int i,j,k;
printf("Enter a number");
scanf("%d",&i);
if(-32768<i && i<32767)
j=i*i;
k=j/(j/2);
printf("%d",k);
}

Is This Answer Correct ?    0 Yes 0 No

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

Answer / prasad

I think this code is execute in turbo c/c++ perfectly.
#inclde<stdio.h>
#include<conio.h>
void main()
{
int a,b;
float x,y;
clrscr();
a=(int)&x;
b=(int)&y;
printf("%d",b-a);
getch();
}

Is This Answer Correct ?    4 Yes 5 No

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

Answer / akash patil

#include<stdio.h>
#include<conio.h>
void main()
{
int a[2];
printf("size is %d",(int)&a[1]-(int)&a[0]);
getch();
}

Is This Answer Correct ?    0 Yes 1 No

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

Answer / learner

#include<stdio.h>
void main()
{
char *ptr1,*ptr2;
char fl;//float,double,int
ptr1 = &fl;//it will take the address of f1
ptr2 = (&fl+1);//it wil increment the address with according thr memory size

printf("%u",(char *)ptr2-(char *)ptr1);//explicit type casting for pointers
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

How do shell structures work?

0 Answers  


Which header file is used for clrscr?

0 Answers  


Why functions are used in c?

0 Answers  


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

0 Answers  


write a program in reverse the string without using pointer,array,global variable declaration,lib fun only using a function?

5 Answers   HCL,


What is C language Terminator?

15 Answers   TCS,


What is the hardest programming language?

0 Answers  


Write programs for String Reversal & Palindrome check

0 Answers   TISL,


How can I convert integers to binary or hexadecimal?

2 Answers  


Is it possible to have a function as a parameter in another function?

0 Answers  


How will you allocate memory to double a pointer?

1 Answers  


1. Write a c pgm to print 1 to 100 without using loops. 2. Write a c pgm for leap year 3. Write a c pgm fibbonacci series,factorial 4. Write a c pgm count no of lines , blanks, tabs in a para(File concept) 5. Write a c pgm to print the letter as per given condition i.e.. if u give 4 out put should b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6.how do get the o/p in number from 1 to 100 in the screen without using control statement? 7. who do u print the word "hello world" without using "printf" statement? 8. write sql program to get the detail of student in a class? Definitions: structure union arrays linkedlist macros directives difference b/w pre processorsDiffrence: 1.Constructors and destructors 2.Structure and Union 3.Array and Lists 4.pre processor... 5. Privillages in C++ 6.structure and union 7.break and continue 8.while and dowhile Pgm..

3 Answers  


Categories