Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of void function returns nothing – C without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I’m starting my studies in C and i came across this function return problem. I created a function that prints the name of numbers up to 9, from an input number. Entering, i have no return from the function. I can’t see where the error is.
This is my code:
void for_loop(int n1, char array[]){ for(int index = n1; index <= 9; index++) { printf("%sn", array[index]); } } int main() { int num1 = 2; char* numbers[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; for_loop(num1, *numbers); return 0; }
Answer
Your code is wrong:
You want this:
void for_loop(int n1, char *array[]) { for (int index = n1; index <= 9; index++) { printf("%sn", array[index]); } } int main() { int num1 = 2; char* numbers[10] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; for_loop(num1, numbers); return 0; }
for_loop(num1, *numbers)
is equivalent to for_loop(num1, numbers[0])
which is equivalent to for_loop(num1, "zero")
.
We are here to answer your question about void function returns nothing – C - If you find the proper solution, please don't forgot to share this with your team members.