[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CVoid

(C) void

Keyword denoting that either

The function returns nothing

void sayHello()
{
  printf("Hello world");
}


The function takes no arguments

(From the C++ MessageBoard, http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=3&MsgID=339047&Setting=P0030F0001, thanks to stober)

In C, int myFunction(void); is the declaration of a function taking no arguments. In C++, int myFunction(); is preferred (see below) to specify this. In C, however, there is a difference between the two, as in C, int myFunction(); denotes a function declaration taking ANY number of unspecified parameter.

Here a (modified) example submitted by stober:

void func1();
void func2(void);
int main(void)
{
  int a = 0;
  int b = 0;
  func1();
  func1(a);  
  func1(a,b);
  func2(a); //Error on this line! func2 has no arguments!
}


The function returns a pointer of unknown data type

void* someFunction();
( Sorry, I haven't got a better example. I need to look in some Win32 API programming for one).

Avoid  ?void* except in low-level code.

See  ?void* for more details.

'void' links



last edited (May 20, 2007) by bilderbikkel, Number of views: 1195, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.