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 improved our website User Interface and other contents. Our next update is adding video tutorials on this site so, We create a new YouTube channel, our YouTube channel name is CodeX.

We need some time for make video tutorials (CodeX) so, stay with us and keep supporting and you know already we make a Collaboration with HackIsOn YouTube channel long time ago So, please Subscribe Our Channels