473,659 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

void keyword

Can anyone please give me a broef explanation of what the void keyword is
for? What does it do? Do I need to use it?

Thanks,
Scott
Nov 16 '05 #1
3 4348
Can anyone please give me a broef explanation of what the void keyword is
for? What does it do? Do I need to use it?


The most common use is to have it as the return type of methods that
don't return a value.

void Foo()
{
// don't return anything
}

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
hi
When used as the return type for a method, void specifies that the method
does not return a value.
void is not allowed in a method's parameter list. A method that takes no
parameters and returns no value is declared as follows:

void MyMethod();
{

}
regards
Ansil
an****@gmail.co m

"Scott" wrote:
Can anyone please give me a broef explanation of what the void keyword is
for? What does it do? Do I need to use it?

Thanks,
Scott

Nov 16 '05 #3
Many languages have a separate syntax for methods that return a value vs
those that don't. VB and VB.NET hav Sub vs Function, FoxPro has Procedure
vs Function, etc. C# just has a function syntax with a faux return type,
void, to indicate that nothing is to be returned. This is characteristic of
all C-family languages including Java and C++.

--Bob

"Scott" <Sc***@discussi ons.microsoft.c om> wrote in message
news:11******** *************** ***********@mic rosoft.com...
Can anyone please give me a broef explanation of what the void keyword is
for? What does it do? Do I need to use it?

Thanks,
Scott

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2652
by: codeslinger | last post by:
What is the point of the construct in the subject line? Why the use of two const labels? Does that do something different than const void *x? And what would void * const x indicate? Thanks in advance :) -- Tobias DiPasquale
188
17316
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
2
3479
by: Marcus Kwok | last post by:
Is there a difference between using the C++ keyword "void" and using "System::Void" when specifying parameters and return types? Is there a preference when choosing between the two? In the code I'm working on, the original author uses both, and I don't understand if there is a specific reason to choose one over the other in certain situations. -- Marcus Kwok
18
2129
by: Giannis Papadopoulos | last post by:
According to the standard (ISO C99 draft WG14/N1124), void is the incomplete type that cannot be completed and comprises the empty set of values. Since it declares the absense of a value can it be considered a data type? Regarding void*, is it just a simple reuse of the same keyword (void) or they have a closer relationship? I could think of only one - a pointer to an incomplete type. However, if one could say that void is the absense...
3
14492
by: vijay.gandhi | last post by:
Hi, I am trying to convert some unmanaged code (C++) to managed code (using C++/CLI). 1) One of the functions used returns a void* which I need to cast into a handle of a managed object. Can somebody please tell me how. Actually, the function that returns a void* is a part of a MFC class - CPtrList, used in my unmanaged code. I was searching of its equivalent
1
1373
by: SMH | last post by:
Hi All, I am currently making the switch from VB to C#. I understand that the VOID keyword allows creation of a function which doesnt require any parameters and doesn't return a value. Is this then, the equivalentof a SUB in VB? Thank you.
26
521
by: eotcl | last post by:
Dear Group! Is it possible to dereference the void pointer to function pointer, and refer to this pointer later as if it was a function. Thanks.
28
2637
by: lovecreatesbeauty | last post by:
Is the keyword const necessary in the comparison function in qsort and bsearch? int (*compar)(const void *, const void *) If the pointer cannot be dereferenced why worry if the pointed object will be modified?
4
14304
by: ANURAGBAJPAI | last post by:
This is a question in my text book, and the answer is- The keyword void in a function declaration has a significant purpose.When the return type of a function is void , that means the function doesn't return anything.Thus we can say that the purpose of specifying the return type void is that it doesn't return anything. Please explain the answer.
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.