What is the difference between void and int in the C language?

In the C language, “void” and “int” are two distinct data types with the following differences:

  1. int is a type of integer used to represent integer values, which can be positive, negative, or zero. On the other hand, void is a special type that represents no type or no value.
  2. The keyword “int” is commonly used in functions to indicate the return type, which means the function can return an integer value. On the other hand, “void” is used to indicate a function that does not return any value, or to declare a function without parameters.
  3. When declaring a variable in int, you need to specify the data type and size of the variable, while void means not specifying a data type and cannot be directly used to declare variables, only to declare the return type or parameter type of a function.

In general, the ‘int’ is used to represent integer data types, while ‘void’ is used to represent a special case of having no type or value.

 

 

More tutorials

Comprehending Java’s Data Types(Opens in a new browser tab)

What is the purpose of the intval function in PHP?(Opens in a new browser tab)

Converting a Python string to an integer and vice versa.(Opens in a new browser tab)

What is the purpose of the tostring function in C++?(Opens in a new browser tab)

How to initialize a C language second-level pointer?(Opens in a new browser tab)

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds