Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Justine Lam
8,785 PointsWhat does void mean in C?
Was doing a google search but couldn't find a good explanation. It seems like it's for declaring a function.
1 Answer
Stone Preston
42,016 PointsVoid is used as the return type when declaring a function that doesnt return anything.
If I wrote a function that returned an int I would use int as the return type:
int someFunction(int a, int b) {
int sum = a + b;
return sum;
}
if I wrote a function that doesnt return anything, I would need to use void as the return type
void someFunction(int a, int b) {
//im not returning anything here, just printing it out on screen
int sum = a + b;
printf("%d", sum);
//since nothing is being returned in the function, the return type should be void
}
A lot of the time, the functions you write wont return anything, they just do something.
John Wheal
27,969 PointsJohn Wheal
27,969 PointsDon't forgot that you can also use it for functions that don't take any variables. For example:
int myFunction(void);