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

Segmentation error but I don't know why

#include #include #include #define MAX_SIZE 100 I am trying to quicksort an array of 2D points based upon their distance from the origin but my code hits a Seg fault after the first scanf. typedef struct point{ double…
0
votes
3 answers

Storing small data in a pointer in C?

To keep this simple, I have a struct along the lines of typedef struct foo { void *data; size_t sz; /* various other crap */ } foo_t; but I'm finding about 90% of the time it really just needs to store a byte or at most a short (but, sometimes,…
Bandrami
  • 4,242
  • 1
  • 13
  • 12
0
votes
1 answer

Free array of void pointers in C

I'm implementing a min/max heap in C and am trying to do it in general, since I'll need it for a future project. The idea is to use a 1D array of void* with a generic comparator, int (*cmp) (void*,void*). My structure looks like this: typedef struct…
modulus0
  • 3,798
  • 1
  • 12
  • 10
0
votes
2 answers

passing different structs to a function(using void *)

I need to figure out how to pass two different structs to a function. I tried using void * for the parameter but i am receiving the error: warning: dereferencing 'void *' pointer error: request for member left in something not a structure or…
user2644819
  • 1,787
  • 7
  • 28
  • 41
0
votes
2 answers

Double linked list and void pointers [find method]

i wrote this double linked list with void pointers typedef struct list_el { void *data; struct list_el *prev; struct list_el *next; } list_el; typedef struct linked_list { int n_el; /*number of…
fitzbutz
  • 956
  • 15
  • 33
0
votes
2 answers

Void Function fail (?)

#include void set_b_to_a(int, int); int main() { int a, b; a=1; b = 15; set_b_to_a(a, b); printf("%d", b); } void set_b_to_a(int a, int b) { b=a; } It should return b=1. BUT it returns b=15! What is wrong? Is…
0
votes
1 answer

Remove recursion void function

someone can help me to remove the recursion of this void function ? It doesn't work in some situations. I have tried but I can't get.Thanks. Source: http://www2.dcc.ufmg.br/livros/algoritmos/implementacoes-07.php void ImprimeCaminho(TipoValorVertice…
user2947016
0
votes
2 answers

How to return/save values with void function in C?

I want to save value with void function. In C++ i did somewhat like this: void func(int & a); void func(int & a) { int value; cin >> value; a = value; } int main() { int x; func(x); cout << x; return 0; } How would this…
Zygimantas
  • 25
  • 1
  • 3
  • 6
0
votes
2 answers

Use "self" in void () function

I have this API that I cannot modify in MyViewController.m file: void my_Callback (void* context, xxxxxx::eventType::type eventtype, int code, const myconst) { //do stuff } I need to call this function: -(void) update { self.textbox.test…
0
votes
6 answers

C/C++ - how is (void) used not as a parameter?

I have seen some code in C/C++ that goes like this: void Main(void) And int Main(void) What is the reasoning for this: why is it not a parameter but used in parentheses after the void/int e.t.c name?
Joe
  • 528
  • 5
  • 19
0
votes
1 answer

error accessing/using void pointers in c

So I have this Linked List print function that is giving me the error: error: invalid use of void expression Here's the line that causes this error: printf("[%d] -> ", *(link->pointer)); /*note: i tried to cast it to (int) but still same error.…
ChrisMcJava
  • 2,145
  • 5
  • 25
  • 33
0
votes
2 answers

Repeatedly Running A Function With Different Parameters Each Time

Currently, I have a struct which I've used to create a lot of parameters, then I have to run various functions on all of…
user2760185
0
votes
2 answers

How to use variable in void to declare another variable Java?

So I'm making a Java Util and I am stuck on this part of code. public void getInput(String i){ int i = scan.nextInt() } Why won't this work?
javaboy
  • 57
  • 1
  • 7
0
votes
3 answers

Why is cout not displaying x?

I am learning C++ and I created a simple void function that uses char. I prototyped the function up top, defined it in the int main and tried to output "Your name is " x. Can someone tell me why it only tells me "Your name is" and not the x (john)…
user1808010
  • 141
  • 1
  • 3
  • 11
0
votes
1 answer

C++, writing into output file from another function coming up blank

So I wrote this code with some help from others from this site, now I've hit another wall. The purpose of this CS project is to create a program that takes commands from the input file, and prints characters to form a picture on the output file. I'm…
hanipman
  • 79
  • 1
  • 2
  • 7