Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 1.41 KB

void-cpp.md

File metadata and controls

40 lines (34 loc) · 1.41 KB
title ms.custom ms.date ms.technology ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid author ms.author ms.workload
void (C++) | Microsoft Docs
11/04/2016
cpp-language
language-reference
void_cpp
C++
void keyword [C++]
functions [C++], void
pointers, void
d203edba-38e6-4056-8b89-011437351057
mikeblome
mblome
cplusplus

void (C++)

When used as a function return type, the void keyword specifies that the function does not return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."

If a pointer's type is void *, the pointer can point to any variable that is not declared with the const or volatile keyword. A void pointer cannot be dereferenced unless it is cast to another type. A void pointer can be converted into any other type of data pointer.

A void pointer can point to a function, but not to a class member in C++.

You cannot declare a variable of type void.

Example

// void.cpp  
void vobject;   // C2182  
void *pv;   // okay  
int *pint; int i;  
int main() {  
   pv = &i;  
   // Cast optional in C required in C++  
   pint = (int *)pv;  
}   

See also

Keywords
Fundamental Types