Advertisement
dllbridge

Untitled

May 9th, 2025
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include   <stdio.h>
  5. #include  <iostream>
  6. using namespace std;
  7.  
  8. void _swap(int   &  , int   &  );
  9. void _swap(float &f1, float &f2);
  10.  
  11. template <typename T> void _swap   (T &, T &);
  12. template <typename T> void monitor (T &, T &);
  13.  
  14.  
  15.  
  16.  
  17. ///////////////////////////////////////////////////////
  18. int  main()                                          //
  19. {
  20.  
  21.      int n1 = 1,
  22.          n2 = 2;
  23.      
  24.      float f1 = 1.32,
  25.            f2 = 2.94;  
  26.            
  27.      char  c1 = 'Y',
  28.            c2 = 'Q';            
  29.      
  30.      _swap(n1, n2);
  31.    
  32.      
  33.     // printf("Address of n1        = %d\n", &n1);
  34.      
  35.      printf("n1 = %d\n", n1);
  36.      printf("n2 = %d\n", n2); _swap(f1, f2);
  37.      printf("f1 = %f\n", f1);
  38.      printf("f2 = %f\n", f2); _swap(c1, c2);    
  39.      printf("c1 = %c\n", c1);
  40.      printf("c2 = %c\n", c2);  
  41.    
  42.      monitor(c1, c2);    
  43. }
  44.  
  45.  
  46. template <typename T>
  47. ///////////////////////////////////////////////////////
  48. void monitor(T &n1, T &n2)
  49. {
  50.  
  51.      cout << "param 1 = " << n1 << endl;
  52.      cout << "param 2 = " << n2 << endl;
  53. }
  54.  
  55.  
  56.  
  57.  
  58. template <typename T>
  59. ///////////////////////////////////////////////////////
  60. void _swap(T &n1, T &n2)
  61. {
  62.    
  63.      printf("Template foo is worked\n");
  64.  
  65.      T   n  = 0;
  66.  
  67.          n  = n1;
  68.          n1 = n2;
  69.          n2 = n;   
  70. }
  71.  
  72.  
  73. ///////////////////////////////////////////////////////
  74. void _swap(int &n1, int &n2)
  75. {
  76.  
  77.     // printf("Address of n1 (swap) = %d\n", &n1);
  78.  
  79.      int n  = 0;
  80.  
  81.          n  = n1;
  82.          n1 = n2;
  83.          n2 = n;
  84. }
  85.  
  86.  
  87.  
  88.  
  89. ///////////////////////////////////////////////////////
  90. void _swap(float &f1, float &f2)
  91. {
  92.  
  93.  
  94.      float f  = 0;
  95.  
  96.          f  = f1;
  97.          f1 = f2;
  98.          f2 = f;
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement