Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is void a data type in C?

Tags:

c

types

void

Is void a data type in the C programming language? If so, what type of values can it store? If we have int, float, char, etc., to store values, why is void needed? And what is the range of void?

like image 924
suhel Avatar asked Aug 15 '10 14:08

suhel


People also ask

What is C type void?

The void type, in several programming languages derived from C and Algol68, is the type for the result of a function that returns normally, but does not provide a result value to its caller. Usually such functions are called for their side effects, such as performing some task or writing to their output parameters.


1 Answers

Void is considered a data type (for organizational purposes), but it is basically a keyword to use as a placeholder where you would put a data type, to represent "no data".

Hence, you can declare a routine which does not return a value as:

void MyRoutine(); 

But, you cannot declare a variable like this:

void bad_variable; 

However, when used as a pointer, then it has a different meaning:

void* vague_pointer; 

This declares a pointer, but without specifying which data type it is pointing to.

like image 80
James Curran Avatar answered Oct 21 '22 07:10

James Curran