Pages

Friday, July 19, 2013

Write a program of Void function with a Parameter in C++

This program demonstrates that one function can be called multiple times

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    #include <iostream.h>
    #include <conio.h>
    // Prototype Declarations
       void printOne (int x);
    int main()
    {
      // First call
      int a = 5;
      printOne (a);
      
      // Second Call
      a = 33;
      printOne (a);
      
      // Done. return to operation system.
     return 0;   
        }// main
/*========= printOne ===============
 print one integer value.
       pre x contains number to be printed 
       post value in x printed     */
    void printOne (int x)
    {
         cout << x << endl;
         getch();
         return ;
         } //printOne  

Results:

5
33

No comments:

Post a Comment