Declaring a function within the main() function in C language

By: IncludeHelp, on 03 MAR 2017

Learn: How to declare a function within main() function and how to define it outside of main().

In the previous post [Correct way to declare and define a function in C], I have discussed a function should be declared before the main() function, but we can also declare a function within the main() function.

Remember: Function can be declared within the main() only. But, function definition should be outside of the main(), after the main() function body.

Consider this example

#include <stdio.h>

int main()
{
	//function declaration
	void printText(void);
	
	printf("I am going to call the function...\n");
	printText();
	printf("Bye bye!!!\n");
	
	return 0;
	
}

//function definition
void printText(void)
{
	printf("Hello friends\n");
}

Output

I am going to call the function...
Hello friends 
Bye bye!!!



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.