Advertisement
Niloy007

Function, Pointer & Structure

Nov 18th, 2020
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct Person {
  5.     char name[20];
  6.     int id;
  7.     float money;
  8. };
  9.  
  10. void personInfo(struct Person employee) {
  11.     printf("Name: %s\n", employee.name);
  12.     printf("ID: %d\n", employee.id);
  13.     printf("Money: %lf\n", employee.money);
  14.     printf("\n");
  15. }
  16.  
  17. int main() {
  18.     struct Person employee[3], student[4];
  19.    
  20.     strcpy(employee[0].name, "Ashik");
  21.     employee[0].id = 1;
  22.     employee[0].money = 450.50;
  23.  
  24.     strcpy(employee[1].name, "XYZ");
  25.     employee[1].id = 2;
  26.     employee[1].money = 560.08;
  27.  
  28.     strcpy(employee[2].name, "ABC");
  29.     employee[2].id = 3;
  30.     employee[2].money = 430.44;
  31.  
  32.  
  33.     strcpy(student[0].name, "S1");
  34.     student[0].id = 1;
  35.     student[0].money = 450.50;
  36.  
  37.     strcpy(student[1].name, "S2");
  38.     student[1].id = 2;
  39.     student[1].money = 560.08;
  40.  
  41.     strcpy(student[2].name, "S3");
  42.     student[2].id = 3;
  43.     student[2].money = 430.44;
  44.  
  45.     strcpy(student[3].name, "S4");
  46.     student[3].id = 4;
  47.     student[3].money = 430.44;
  48.  
  49.     printf("Employee Type:\n");
  50.     for (int i = 0; i < 3; i++) {
  51.         personInfo(employee[i]);
  52.     }
  53.  
  54.     printf("Student Type:\n");
  55.     for (int i = 0; i < 4; i++) {
  56.         personInfo(student[i]);
  57.     }
  58. }
  59.  
  60. // void swap(int *p, int *q) {      // Call by Reference
  61. //  int temp = *p;
  62. //  *p = *q;
  63. //  *q = temp;
  64. // }
  65.  
  66. // void swap(int p, int q) {        // Call by value
  67. //  int temp = p;
  68. //  p = q;
  69. //  q = temp;
  70. //  printf("Inside Function: %d %d\n", p, q);
  71. // }
  72.  
  73. // int main() {
  74. //  int a, b;
  75. //  scanf("%d %d", &a, &b);
  76.  
  77. //  printf("Before change: %d %d\n", a, b);
  78.     // swap(&a, &b);         // Call by Reference
  79.  
  80. //  printf("After change: %d %d\n", a, b);
  81. // }
  82.  
  83. // int main() {
  84. //  int a, b;
  85. //  scanf("%d %d", &a, &b);
  86. //  int *p;
  87. //  p = &a;
  88. //  printf("Before Change: %d\n", *p);
  89.  
  90. //  p = &b;
  91. //  printf("After Change: %d\n", *p);
  92. // }
  93.  
  94. // int func(int x) {
  95. //  if(x % 2 == 0) {
  96. //      return 1;
  97. //  } else {
  98. //      return 0;
  99. //  }
  100. // }
  101.  
  102.  
  103. // int main() {
  104. //  int n;      // Local variable
  105. //  scanf("%d", &n);
  106.  
  107. //  int ans = func(n);
  108.  
  109. //  if(ans) {
  110. //      printf("Even\n");
  111. //  } else {
  112. //      printf("Odd\n");
  113. //  }
  114. // }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement