I am learning cs50 through EdX. In week2-lec1, while explaining user defined functions, Prof David used void along with the function GetPositiveInt as arg.

If void is used for functions, not returning any value, but just doing something why was it used? This function was returning the value of n to the main function. I'd also like to know where in the code it was used.

1 Answer 1


The keyword void actually has different meanings in different contexts. When the return type of a function is void, this means that the function doesn't return any value. For example

void foo(void)
    // return 10; // compile-time error

Notice also that void is used between the parentheses when defining a function to indicate that this function does not take any arguments. For example,

void bar(void)
    // some code

// client code
// bar(10); // compile-time error

For more info, watch the short on functions!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .