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
4 answers

how to print void in java

The below statement returns void Pattern lazy = Pattern.compile("X??"); Matcher lazyMatcher = lazy.matcher("X"); if (lazyMatcher.matches()) { System.out.println(lazyMatcher.group()); } Is there way to print void in java. I tried below 2…
upog
  • 4,965
  • 8
  • 42
  • 81
0
votes
2 answers

How to test standard output string in other java file in Java?

So, in brief: I have a method that is void, and prints stuff to standard output. I have a second file that tests the output of functions against what it should be and returns true if they all pass. I have a makefile that checks the output of the…
0
votes
2 answers

Void Function Error?

So I had to write a program that used the Pythagorean Threes concept where if you entered a number it would give you all the combinations less than that number that would produce a correct a^2 + b^2 = c^2 output. Not sure if I explained the…
0
votes
4 answers

Change method from return to void

I am asked to make a maze game in c++ (using codeblocks). I figured out most of it, but stuck in one method of Maze class. I have this function to say that travel in anyone direction (up, down, left, right) where you dont get the wall. int…
userabc55478
  • 61
  • 1
  • 8
0
votes
1 answer

How to return variables from static void methods

I'm new to C# and strongly typed languages. I'm doing an assignment for university and my program now works as intended. But, I changed 2 static void method headings to have return types not realising doing so will result in marks being deducted.…
user2281248
  • 13
  • 3
  • 8
0
votes
3 answers

how to make a void returning a datatable?

I want to use multithreading for the first time as I understood, there is 2 laws to respect: -Threads can be used only with void's -One cannot use Threads to change something in a windows form(unless you use delegates). So I code my macro by respect…
francops henri
  • 507
  • 3
  • 17
  • 29
0
votes
1 answer

Invalid void error and illegal modifier error

I keep getting this error: Illegal modifier for the local class myWebClient; only abstract or final is permitted. and this error: void is an invalid type for the variable backButtonClicked Heres the code where the error occurs. public class…
Tssomas
  • 362
  • 1
  • 4
  • 16
0
votes
0 answers

Php - character returned by file_get_contents

i'm using file_get_contents to retrieve the content of external webpages and then i log the received content into a txt file. The problem is i've founded some void in the middle of the page, and since that part of page is a human written text i…
user2540463
  • 112
  • 1
  • 3
  • 10
0
votes
1 answer

How do i pass in a delegate as a parameter

I want to pass in a void or an int/string/bool(Which returns a value) Dynamically like so. Delay(MyVoid);//I wont to execute a delay here, after the delay it will execute the the param/void like so... public static void MyVoid() { …
Daniel Jones
  • 109
  • 1
  • 2
  • 9
0
votes
3 answers

Understanding pthread_ create arguments in C

In this below link https://computing.llnl.gov/tutorials/pthreads/samples/hello.c in the statement rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); the coder has just passed a variable as 4th argument without passing address of that…
user1762571
  • 1,888
  • 7
  • 28
  • 47
0
votes
1 answer

Accepting return type void from a method?

i am developing a testing class, which allows users to put in arbitrary method calls. Then my class will trigger them. static class UserClass { static String method_01() { return ""; } static void method_02() {} } class MyTestUtil { …
midnite
  • 5,157
  • 7
  • 38
  • 52
0
votes
3 answers

cast void* to a struct with an array member

I'm trying to directly cast a stream of data into a structure that actually has a variable number of other structures as members. Here's an example: struct player { double lastTimePlayed; double timeJoined; }; struct…
megamau
  • 33
  • 5
0
votes
7 answers

Void and return in Java - when to use

I have some "confusion" about void and return. In general, I understand void is used in methods without returning anything, and return is used in methods when I want to return something to the calling code. But in the following code, I can use both,…
user2026884
  • 47
  • 1
  • 1
  • 6
0
votes
6 answers

Can I re-cast an entire array from *void to *int?

I have a function which reads a binary file into memory as type void *. Information in the file header indicates the amount of memory required and the actual data type (in bytes per number - eg. 8 if it should be interpreted as "long". My problem…
JWDN
  • 382
  • 3
  • 13
0
votes
2 answers

PHP Json decode is ok, but decoded values are void

I used this code to decode json, sent with curl (POST): $json_obj = json_decode( file_get_contents('php://input')); // JSON as obj var_dump($json_obj); $id_a = $json_obj -> {'$id_a'}; $id_b = $json_obj -> {'$id_b'}; $value = $json_obj ->…
user2452426
  • 991
  • 1
  • 7
  • 7
1 2 3
99
100