Advertisement
dllbridge

Untitled

Apr 10th, 2024
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.08 KB | None | 0 0
  1.  
  2. #include   <stdio.h>
  3.  
  4. int n = 5;
  5.  
  6. ///////////////////////////////////////////////////
  7. int main()
  8. {
  9.    
  10.     int *p = &n;
  11.    
  12.    
  13.     printf("address n = %d\n",  p);
  14.     printf("        n = %d\n", *p);
  15. }
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. /*
  36.  
  37.  
  38.  
  39. #include   <stdio.h>
  40.  
  41.  
  42. struct Cdog
  43. {
  44.    
  45.     int   nAge;
  46.    
  47.     float fWeight; 
  48.    
  49. } dog1, dog2;
  50.  
  51.  
  52.  
  53. Cdog dog3, dog4;
  54.  
  55.  
  56. void fDog(Cdog *p);
  57.  
  58.  
  59. ///////////////////////////////////////////////////
  60. int main()
  61. {
  62.    
  63.     Cdog dog5, dog6;
  64.    
  65.    
  66.    
  67.     dog3.nAge    =   3;
  68.     dog3.fWeight = 0.2;
  69.  
  70.     dog6.nAge    =  11;
  71.     dog6.fWeight = 1.241;
  72.  
  73.     fDog(&dog6);
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. ///////////////////////////////////////////////////
  81. void fDog(Cdog *p)
  82. {
  83.    
  84.      printf("nAge    = %d  \n", p->nAge   );
  85.      printf("fWeight = %.3f\n", p->fWeight);
  86. }
  87.  
  88. */
  89.  
  90.  
  91.  
  92.  
  93. /*
  94. #include   <stdio.h>
  95.  
  96.  
  97.  
  98. void swap(int &p1, int &p2);  
  99. void print(int *p, int n);
  100.  
  101. ///////////////////////////////////////////////////
  102. int main()
  103. {
  104.    
  105.     int nArr[99] = {5, 11, 2, 6, 34, 1, 7};
  106.  
  107.     swap(nArr[0], nArr[4]);
  108.    
  109.     print(nArr, 7);
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. ////////////////////////////////////////////////////
  127. void print(int *p, int n)
  128. {
  129.    
  130.      for(int i = 0; i < n; i++)
  131.      {
  132.            
  133.           printf("%d, ", p[i]);    
  134.      }
  135.     printf("\n");
  136. }
  137.  
  138.  
  139.  
  140. ///////////////////////////////////////////////////
  141. void swap(int &r1, int &r2)                       //
  142. {
  143.    
  144.      int n  = r1;
  145.          r1 = r2;
  146.          r2 = n ;
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. */
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. /*
  167.  
  168. #include   <stdio.h>
  169.  
  170.  
  171.  
  172. void swap(int *p1, int *p2);  
  173. void print(int *p, int n);
  174.  
  175. ///////////////////////////////////////////////////
  176. int main()
  177. {
  178.    
  179.     int nArr[99] = {5, 11, 2, 6, 34, 1, 7};
  180.  
  181.     swap(&nArr[0], &nArr[4]);
  182.    
  183.     print(nArr, 7);
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. ////////////////////////////////////////////////////
  201. void print(int *p, int n)
  202. {
  203.    
  204.      for(int i = 0; i < n; i++)
  205.      {
  206.            
  207.           printf("%d, ", p[i]);    
  208.      }
  209.     printf("\n");
  210. }
  211.  
  212.  
  213.  
  214. ///////////////////////////////////////////////////
  215. void swap(int *p1, int *p2)                       //
  216. {
  217.    
  218.    
  219.      int n = *p1;
  220.      
  221.      *p1 = *p2;
  222.      
  223.      *p2 = n;
  224.    
  225. }
  226.  
  227.  
  228.  
  229. */
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250. /*
  251. #include  <iostream>
  252. #include  <string.h>
  253. #include   <stdio.h>
  254. using namespace std;
  255.  
  256.  
  257.   struct Dog
  258.   {
  259.        int  Age;
  260.        char color[99];
  261.       float weight;
  262.        
  263.   };
  264.  
  265.  
  266. void foo(Dog *p);
  267.  
  268.  
  269. ///////////////////////////////////////////////////
  270. int main()
  271. {
  272.    
  273.    Dog y, u, w;
  274.    
  275.    y.Age = 4;
  276.    u.Age = 8;
  277.    w.Age = 5;
  278.    
  279.    w.weight=0.20;
  280.    strcpy(w.color, "Blue" );
  281.    strcpy(u.color ,"brown"  );
  282.  
  283.    y.color[0] = 'B';
  284.    y.color[1] = 'l';
  285.    y.color[2] = 'a';
  286.    y.color[3] = 'c';
  287.    y.color[4] = 'k';
  288.    y.color[5] =  0 ;              
  289.      
  290.    
  291.    foo(&w);
  292.  
  293.    
  294. }
  295.  
  296. //////////////////////////////////////////////////////////
  297. void foo(Dog *p)                                        //
  298. {
  299.    
  300.     printf("u.color  = %s\n"  , p->color );
  301.     printf("u.Age    = %d\n"  , p->Age   );
  302.     printf("w.weight = %.2f\n", p->weight);
  303. }
  304.  
  305.  
  306.  
  307. */
  308.  
  309.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement