Home > Backend Development > C++ > What does void mean in c language?

What does void mean in c language?

下次还敢
Release: 2024-05-02 20:06:29
Original
494 people have browsed it

void means null or no value in C language. It is mainly used to specify that the function has no return value or represents the null value of the pointer. The latter can store general pointer values, such as function pointers or callback functions.

What does void mean in c language?

The meaning of void in C language

void means empty or no value in C language, it has Two main uses:

1. Specify that the function has no return value

If the function does not return any value after execution, its return type can be specified as void. For example:

<code class="c">void print_hello() {
  printf("Hello, world!\n");
}</code>
Copy after login

2. Represents the null value of a pointer

is similar to other pointer types such as int, void can point to any type of variable. However, unlike other pointers, void* pointers cannot be dereferenced to obtain the value pointed to by a variable and can only be used to store general pointer values, such as function pointers or callback functions. For example:

<code class="c">void* ptr;
ptr = malloc(sizeof(int));</code>
Copy after login

In this example, ptr points to an allocated memory block, but it does not know the type stored in that memory block.

The above is the detailed content of What does void mean in c language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template