Difference between void and void*

Asked

Viewed 818 times

1

What is the difference between void* and void as type of return of a function?

Example 1:

void *func_nome(int param){
      ...
  }

Example 2:

void func_nome(int param){
      ...
  }
  • @Luizvieira gave to understand what is (void *) but and the (void) ? and in relation to being a function, and not a variable

  • Vc means in relation to the "return" of a function (functions receive 0 or more values and return a value). Either as a return or as a parameter, the type of values involved need to be defined. And there is the distinction, which is already explained in the other question. It was not clear that you also did not know what the void alone means. Considering this, I took my vote to close.

  • I found the answer in http://answall.com/questions/97138/qual-%C3%A9-a-finalidade-do-void-em-c

1 answer

3

When declaring a function in C, C++ (and other derived languages such as Java and C#) it is always necessary to declare the function return type. void is a special type to indicate that the function does not return any value. It literally means "nothing". This is what some other languages (such as Pascal) would define as a procedure (procedure).

Whichever tipo* indicates a pointer for that type. For example: int* is a pointer to integer and char* is a pointer to character. But void* is not a pointer to "nothing". It is a special case. It indicates a pointer to any type, as if it were a joker. It is used when it is not known what type of data is being pointed out. It is used, for example, as function return malloc, because the memory it allocates can be used for any type of data. It is up to the programmer to then coerce to the desired type.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.