Can U write a C-program to print the size of a data type
without using the sizeof() operator? Explain how it works
inside ?

Answer Posted / sanjay bhosale

// SizeOperator.cpp : main project file.
// Program : To implement sizeof operator

#include "stdafx.h"
#include<stdio.h>
#define sizeof_op1(val) ((char *)(&(val) + 1) - (char *)&(val))// for variable
#define sizeof_op2(type) ((type *)0) + 1//((type *) (10) + 1) - (type *) (10) // for type

using namespace System;

int main(array<System::String ^> ^args)
{
int i=0;
char ch = 'a';
float f = 1.00f;

printf("\nSize of int : %d %d",sizeof_op2(int),sizeof(int));
printf("\nSize of char : %d %d",sizeof_op2(char),sizeof(char));
printf("\nSize of float : %d %d",sizeof_op2(float),sizeof(float));
printf("\nSize of long : %d %d",sizeof_op2(long),sizeof(long));
printf("\nSize of short : %d %d",sizeof_op2(short),sizeof(short));
printf("\nSize of double : %d %d",sizeof_op2(double),sizeof(double));
printf("\nSize of long double : %d %d",sizeof_op2(long double),sizeof(long double));

printf("\nsize of int variable :%d %d",sizeof_op1(i),sizeof(i));
printf("\nsize of char variable :%d %d",sizeof_op1(ch),sizeof(ch));
printf("\nsize of float variable :%d %d",sizeof_op1(f),sizeof(f));
//Console::WriteLine(L"Hello World");
getchar();
return 0;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does emoji p mean?

595


The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration

625


What is the condition that is applied with ?: Operator?

654


What is the use of getchar() function?

624


Describe newline escape sequence with a sample program?

647






What is an auto keyword in c?

636


Explain what are binary trees?

604


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

1644


Why c is a procedural language?

578


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

916


Is return a keyword in c?

594


How would you use the functions fseek(), freed(), fwrite() and ftell()?

698


What are the types of functions in c?

568


Explain what header files do I need in order to define the standard library functions I use?

645


What are the different properties of variable number of arguments?

659