Subscribe

RSS Feed (xml)

Friday, September 30, 2011

C Data type - void

Linguistic meaning of void is nothing. Size of void data type is meaningless question.

What will be output of following c code?
#include<stdio.h>
int main(){
    int size;
    size=sizeof(void);
    printf("%d",size);
    return 0;
}

Output: Compilation error

If we will try to find the size of void data type complier will show an error message “not type allowed”. We cannot use any storage class modifier with void data type so void data type doesn’t reserve any memory space. Hence we cannot declare any variable as of void type i.e.
void num;   //compilation error

Use of void data type

1. To declare generic pointer
2. As a function return type
3. As a function parameter.    

6 comments:

  1. The word void is used in the sense of empty rather than that of invalid.The another used of void is to declare the pointer in C/C++ where It is not sure what data type is addressed by the pointer.

    ReplyDelete
  2. i was searching that script for my programm.
    thanks for sharing.

    ReplyDelete
  3. Thanx for this piece of code. It saved me a lot of time.
    http://www.intellectsoft.net/

    ReplyDelete
  4. http://letsplaywithc.wordpress.com/

    ReplyDelete
  5. Best C Programs with Complete Explanation
    Visit Here ►► Lightning Code

    ReplyDelete
  6. Wow..!! This is an adorable post as the information shared in this post is very helpful. I am thankful to get this post when I was searching a web developer and mobile app developer

    ReplyDelete