Questions tagged [void]

An incomplete type used as syntactic place-holder for the return type of a method/function when no value is returned.

Programming languages derived from C or Algol68, like C++, C#, Java, etc., may define the return type of methods/functions as void when the method/function does not return a value, but simply completes execution.

An example of its use in Java, compared to a non-void method, is:

int nonVoidMethod {
    // do something
    return 0; // return a value to the caller
}

void voidMethod {
    // do something
    return; // no value allowed to be returned from a void method
    // a "return" statement is not required
}

Although void is used as a type, it's an incomplete type:

  • In some languages, such as Java and Algol68, void is only a keyword used as a return type. It is not considered as a valid type in other language constructs.

  • Other languages, like C and C++, consistently define void as a type with an empty set of values. This allows its use for example in compound type constructs (void pointers). But no void objects can be instantiated.

1913 questions
0
votes
2 answers

what does the *(void**) means

I have seen a class like this on the internet, the head file #ifndef _COMMON_ARRAY_OBJECT_POOL_H_ #define _COMMON_ARRAY_OBJECT_POOL_H_ #include namespace easynet { class ArrayObjectPool { public: /** construct * @param…
Ethan
  • 461
  • 4
  • 13
0
votes
3 answers

Android pass object not its value

How can I update String object from void? Now it gives me an error: The final local variable sObj cannot be assigned, since it is defined in an enclosing type. String object = ""; String object2 = ""; String object3 = ""; String object4 = ""; String…
mgulan
  • 795
  • 1
  • 14
  • 33
0
votes
3 answers

Calling a method from a class in Java

Basically, I am making a gambling game. It asks the person how much they want to bet, then if they are right, their 'wallet' increases by however much they win back, depending on the odds given. I am using a class exclusively for the persons…
0
votes
4 answers

Java - How to access an array created in a void function

Thanks to those that helped me get this far. I made some changes. Now there is an error on the line where array1 is assigned in the method, Method(). (edited version show below) public class JavaApplication2 { int[] array1; public…
SilverF0x
  • 67
  • 1
  • 13
0
votes
3 answers

Why am I getting a "void value not ignored as ought to be" error?

First, I would like to state that I am working on a homework problem, and as a result of this I would really appreciate it if any answers given were not simply answers, but explanations. Also, if you're worried about helping with homework problems,…
shermanzach
  • 591
  • 1
  • 6
  • 14
0
votes
1 answer

java - call a void method then pass the object on one line

Here is something I've been wanting to know for a long time now. Is it possible to pass an object but first call a void method on that object in the same line? It is quite hard to explain but I'll give an example: I'm using a Vector object from a…
werter318
  • 55
  • 1
  • 8
0
votes
5 answers

How safe is reading a void * pointing to a char as an int?

How safe is reading a void * pointing to a char as an int? Example: To test the first bit of a char in a system where 8 bit chars are much slower to access than 32 bit ints. char c = 'B'; // a char here to illustrate the potentially dangerous case,…
jayjay
  • 1,017
  • 1
  • 11
  • 23
0
votes
1 answer

The type arguments for method cannot be inferred from the usage. (c#, lambda)

Firstly, I am a complete beginner to advanced level programming. All I have done are tutorials to C++ found on the web. I'm facing this problem at work. I have seen similar queries but nothing has helped me understand. Please note: I am terrible at…
user3207920
  • 5
  • 1
  • 6
0
votes
1 answer

Running a void method from a different class using actionlistener for my menu combobox.

I am creating a little combobox menu for my ap comp sci project. This is my first time working with GUI so I am still familiarizing myself with it. I have a menu class and a few other classes that run mostly void methods to do simple things like…
0
votes
5 answers

Confused on calling method with without void

I'm having trouble understanding the result of using void when calling a method. Below is a main() that calls a test(). The test() has a return of void. If I call void test() (use void) the execution seems to stop: no print from test() If I call…
Playing with GAS
  • 565
  • 3
  • 10
  • 18
0
votes
4 answers

What does this do exactly? [*(char*)p1]

I am not used to pointers because I started learning Pascal in high school and now I am upgrading myself to C. My request would be to explain me what should I think when I see something like this [*(char*)p1]. Don't be shy writing me quite a few…
MaXiMkA
  • 449
  • 3
  • 6
  • 14
0
votes
1 answer

C: Reading int** from void*

so im trying to define a generic ADT. i have a struct that looks like this: struct grid_type{ void* table; int startX, startY, endX, endY, xDim, yDim; }; as you can see i have a void pointer which should be able to store various data…
Felix Kreuk
  • 193
  • 1
  • 9
0
votes
2 answers

Modifying an object or primitive using a void method

Consider line 2 and line 3 in the following code..... class ModifyObjects { static void modifyString1(String s){ s = "xyz"; //Or any other operations } static String modifyString2(String s){ s = "xyz"; return…
0
votes
0 answers

Using a void pointer as a function paramenter in C

I'm trying to create a type generic function in C. As an argument I was passing on a void pointer. (The programmer using the function would be able to pass on a pointer of any type). However, this of course presents problems when dereferencing said…
user3126802
  • 419
  • 8
  • 19
0
votes
1 answer

Why can't I set a value inside of this class?

I have a class: class SendData { public: SendData(int SendAMsg(int foo, unsigned char *bar, int length), int number) { m_nDefinePos = 0; m_nOtherStuffDefinedAs =0; } void somestuffhere(); void…
Zett
  • 43
  • 5