This blog is under construction

Saturday, 12 May 2012

Void function in C

What is void function?
If a function returns nothing to the calling function, then it is called void function.  But still, we can indirectly return values to the calling function using global variables and pointers.  The return type of the function would be void instead of any other data type.

Void function example in C:
void func(int a, int b);

Here, void is the return type which means the function func() won't return anything.

Example C program to illustrate void function:
 
  #include <stdio.h>
  void update();
  int num1, num2;
  int main() {
        num1 = 100;
        num2 = 200;
        printf("Before update() function call:\n");
        printf("Value of num1:%d\n", num1);
        printf("Value of num2:%d\n\n", num2);
        update();
        printf("After update() function call:\n");
        printf("Value of num1:%d\n", num1);
        printf("Value of num2:%d\n", num2);
        return 0;
  }

  void update() {
        num1 = num1 + 100;
        num2 = num2 + 100;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Before update() function call:
  Value of num1:100
  Value of num2:200

  After update() function call:
  Value of num1:200
  Value of num2:300



1 comment:

  1. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete