RicardasSim

testing arguments, array, enum

Feb 16th, 2023
1,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. //linux, 64bit, gcc, -Wall -Wextra -Wpedantic -Wshadow
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. typedef struct TestStruct {
  8.     int a;
  9.     int b;
  10.     int c;
  11. } TestStruct;
  12.  
  13. typedef enum TestEnum {
  14.     E_0 = 0,
  15.     E_1 = 1,
  16.     E_2 = 2
  17. } TestEnum;
  18.  
  19. void f0( TestStruct s )
  20. {
  21.     printf( "%d  %d  %d\n", s.a, s.b, s.c );
  22. }
  23.  
  24. void f1( int* p, unsigned int n )
  25. {
  26.     for ( unsigned int i = 0; i < n; ++i )
  27.     {
  28.         printf( "%d  ", p[i] );
  29.     }
  30.  
  31.     printf( "\n" );
  32. }
  33.  
  34. void f2( TestEnum *e, unsigned int n )
  35. {
  36.     for ( unsigned int i = 0; i < n; ++i )
  37.     {
  38.         printf( "%d  ", e[i] );
  39.     }
  40.  
  41.     printf( "\n" );
  42. }
  43.  
  44. int main()
  45. {
  46.  
  47.     TestStruct s = { 1, 2, 3 };
  48.  
  49.     f0( s );
  50.  
  51.     f0( (TestStruct){ 4, 5, 6 } );
  52.  
  53.  
  54.     int arr[]={ 1, 2, 3 };
  55.  
  56.     f1( arr, 3 );
  57.  
  58.     f1( (int[]){ 4, 5, 6 }, 3 );
  59.  
  60.     TestEnum te[] = { E_0, E_2 } ;
  61.  
  62.     f2( te, 2 );
  63.  
  64.     f2( (TestEnum[]){ E_2, E_1 }, 2 );
  65.  
  66.  
  67.     return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment