Functions Classification in C

Previous
Next

Functions classified into:

  1. No arguments No return values
  2. With argument No return values
  3. With arguments With return values
  4. No argument with return values
  5. Recursion

No arguments and No return values:

  • In this case, the function is not taking any input and not giving output as well.
  • “void” is a keyword.
  • “void” represents “nothing” in programming.
  • We can specify the void keyword to explain the function is not taking input and returning output.

Note: OS invokes main() function implicitly. Other functions must be called manually. If we don’t call, the function logic never executes.

#include<stdio.h>
void test(void);
int main()
{
	printf("Starts with main... \n");	
	return 0;
}
void test(void)
{
	printf("test function...\n");
}
  • Program execution starts with main() function and ends with main() only.
  • Control moves from one location to another location to execute the code.
#include<stdio.h>
void test(void);
int main()
{
	printf("Starts with main... \n");	
	test();
	printf("Ends with main...\n");
	return 0;
}
void test(void)
{
	printf("test function...\n");
}
  • We can define multiple functions in a single program.
  • We can call the functions in any order once we defined.
  • We can call the functions n number of times after definition.
#include<stdio.h>
void fun1(void);
void fun2(void);
int main()
{
	printf("Main logic... \n");	
	fun2();
	fun2();
	fun1();
	fun2();
	return 0;
}
void fun1(void)
{
	printf("fun1 logic...\n");
}
void fun2(void)
{
	printf("fun2 logic...\n");
}
Previous
Next

Add Comment

Courses Enquiry Form