What does void mean in c




















Nick Katsivelos Nick Katsivelos 4, 4 4 gold badges 18 18 silver badges 11 11 bronze badges. This question mix 3 languages Add a comment. Active Oldest Votes. Basically it means "nothing" or "no type" There are 3 basic ways that void is used: Function argument: int myFunc void -- the function takes nothing. Cory Nelson Gerald Gerald I'd use "no type" rather than "no size" — Kjetil Joergensen. Earwicker and kjetijor, both good points that I debated on, but my sleepless mind needed help ; Thanks.

Not disagreeing, but an additional use of void is in the "cast to void" trick to suppress warnings for unused values. It's a bit of a stretch since it doesn't really correspond with how the compiler interprets things, but you can interpret that to mean "I'm using this value to do nothing". However, in C, it is NOT optional: foo means it takes any number of parameters of any type, whereas foo void means it takes zero parameters.

Show 4 more comments. Peter Mortensen 29k 21 21 gold badges 97 97 silver badges bronze badges. Johannes Schaub - litb Johannes Schaub - litb k gold badges silver badges bronze badges. What does void p do? I did not quite get what you meant by "usage of value is absent.

Yashas If anyone is also confused about the void var; statement, I've found detailed answers at stackoverflow. Perhaps update for Rust if that is relevant? Robert S. Barnes Robert S. Barnes It indicates the absence of a return value in a function. Rik Rik Think of void as the "empty structure". Let me explain.

You can even decide that "void" is just a synonym for the type represented by the empty structure, rather than a keyword in the language maybe its just a predefined type : Similarly, I can think of a function requiring no values as accepting an empty structure, e.

Ira Baxter Ira Baxter Three usage cases for void: Function signatures. Cases 1 and 2 were already covered by Gerald but case 3 has not been addressed yet. TimF TimF 41 2 2 bronze badges. Just a note in regards to your last sentence - bear in mind that is only true of statically typed languages.

Dynamically typed languages do not need void since their methods may just simply not return anything - the "void" is implied by the lack of anything else being returned. Correction to my last comment - I meant to say last paragraph not sentence. Charlie Charlie 10k 9 9 gold badges 49 49 silver badges 89 89 bronze badges.

Most people don't realise that void maps to the System. Void structure- msdn. So it also can't hold any value. Pang 8, gold badges 82 82 silver badges bronze badges. Void is the equivalent of Visual Basic's Sub. Only as a return type. I can think of three more uses of void: void arguments function takes nothing , void pointers no pointer type specified , and void casts discard value. Hannoun Yassir Hannoun Yassir Python Javascript Linux Cheat sheet Contact.

Basically it means "nothing" or "no type" There are 3 basic ways that void is used: Function argument: int myFunc void -- the function takes nothing. Shortest Hello World program with no semi colons Update.

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu Because it is safer. But if, by mistake, we call it with arguments we want to be warned that they will not be used. It is a pointer, whose type is not known. It could point to an int, char, double, structure or any type.

This is usually done with a helper variable. Note that in order to use the value in a void pointer you need to dereference it. You must know the type of its value in order to dereference it. Void pointers in C are a powerful technique, but use it carefully.



0コメント

  • 1000 / 1000