Global Variables and void function :

Global or External variables :

Variables are declared outside the body of the main program are referred as global variables.

Example :

  1. /* Description: write a simple program use global or external variable */
  2. #include<stdio.h>
  3. int age=23;
  4. main()
  5. {
  6. printf("My age is %d.",age);
  7. getch();
  8. }

Note : Global variable values can be referred in a function. They need not be passed to the function as arguments.

Output :

c language - write a simple program use global or external variable

void function :

A function which does not return a value directly to the calling program is referred as a void function.

Example :

  1. /* Description: write a simple program use void function */
  2. #include<stdio.h>
  3. int m,n;
  4. main()
  5. {
  6. void add(void);
  7. m=10,n=20;
  8. printf("\n m = %d and n = %d",m,n);
  9. add();
  10. printf("\n m = %d and n = %d",m,n);
  11. getch();
  12. }
  13. void add()
  14. {
  15. m = m + 15;
  16. n = n + 15;
  17. }

Note : A void function can also use a return statements without a return value (return;).

Output :

c language - write a simple program use void function

Next Update

Loading...

Currently, we are working on other servers, but soon we update our website with new content. So, stay tuned we are back soon with new content.

Free Courses