top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

why is sizeof() an operator and not a function ?

+2 votes
85 views
posted Sep 6, 2013 by Ganesh Kumar

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button
It's not possible to write a function that can take a type as an argument a function can take only variable as output.

1 Answer

+1 vote
 
Best answer

Sizeof() is a compile time operator. To calculated size of an element (either for inbuilt data type or user defined data type) type information is necessary at the compile time along with operating system information(32 bit or 64 bit). After compilation phase, compiler generates object code. object code doesn't has type information. while executing sizeof() just return calculated size of object then we use malloc, calloc etc function to allocate memory dynamically.

answer Sep 6, 2013 by Vimal Kumar Mishra
Similar Questions
0 votes

Used the sizeof of function, which gives 1; why?
I want to know the size of the entire function. How to achive it?

#include <stdio.h>
void (*p)(int); 
void test_func(int data)
{
  printf("%d\n",data);
}

main(void)
{
    p = test_func;
    (*p)(4);
    printf("%d",sizeof(test_func));
}
+7 votes
#include<stdio.h>

int &fun()
{
   static int x;
   return x;
}   

int main()
{
   fun() = 10;
   printf(" %d ", fun());

   return 0;
}

It is fine with c++ compiler while giving error with c compiler.

+4 votes
#include<stdio.h>
int var;
int var;
int var;

int main(void) { 
  printf("%d \n",var); 
  return 0;
}

Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...