What does "void" do in a program?
What does "void" do in a program?
void doesnt do anything, thats why its void
>What does "void" do in a program?
It defines a type that is completely generic (with restrictions), or defines a function that returns no value. In function parameter lists, void means that there are no parameters.
-Prelude
My best code is written with the delete key.
A type that is completly generic? So, I could have a variable of type void? What could it hold?
>So, I could have a variable of type void? What could it hold?
Note that I said with restrictions. You can't declare a variable of type void, it has to be void *, and that makes it a generic pointer which can be converted into any type. Note that the syntax is a nightmare though.
-Prelude
My best code is written with the delete key.
How large is type void?
So... would the following be considered correct syntax?
void *vVariable;
vVariable = new char[256];
-or-
vVariable = &cVariable;
all pointers regardless of type store the same data, an address. So all pointers are the same size, that of an int.How large is type void?
Last edited by C_Coder; 04-13-2002 at 07:24 AM.
All spelling mistakes, syntatical errors and stupid comments are intentional.
>How large is type void?
The size of an int.
>So... would the following be considered correct syntax?
>void *vVariable;
>vVariable = new char[256];
Yes, actually it would. The problem isn't in allocating memory for a void * but in working with one. To allocate memory to a void *, then assign a value to that memory and print requires syntax like this:
orCode:/* pseudocode */ void *p = new int; *(int *)p = 27; cout<< *(int *)p <<"\n";
-PreludeCode:/* pseudocode */ void *p; int i = 27; p = &i; cout<< *(int *)p <<"\n";
My best code is written with the delete key.