Advertisement
Zinak

call by value,call by referance

Dec 3rd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <stdio.h>
  2. struct student
  3. {
  4. char name[50];
  5. int roll;
  6. };
  7.  
  8. void display(struct student stu);
  9. // ফাংশনের প্রোটোটাইপ(prototype) স্ট্রাকচার ডিক্লেয়ারেশনের নিচে থাকা উচিৎ অন্যথায় কম্পাইলার এরর(error) দেখাতে পারে।
  10.  
  11. int main()
  12. {
  13. struct student stud;
  14. printf("Enter student's name: ");
  15. scanf("%s", &stud.name);
  16. printf("Enter roll number:");
  17. scanf("%d", &stud.roll);
  18. display(stud); //স্ট্রাকচার ভ্যারিয়েবল p stud কে আর্গুমেন্ট হিসাবে অতিক্রম করানো।
  19. return 0;
  20. }
  21. void display(struct student stu){
  22. printf("Output\nName: %s",stu.name);
  23. printf("\nRoll: %d",stu.roll);
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. #include <stdio.h>
  36. struct distance
  37. {
  38. int feet;
  39. float inch;
  40. };
  41. void add(struct distance d1,struct distance d2, struct distance *d3);
  42.  
  43. int main()
  44. {
  45. struct distance dist1, dist2, dist3;
  46.  
  47. printf("First distance\n");
  48. printf("Enter feet: ");
  49. scanf("%d", &dist1.feet);
  50. printf("Enter inch: ");
  51. scanf("%f", &dist1.inch);
  52.  
  53. printf("Second distance\n");
  54. printf("Enter feet: ");
  55. scanf("%d", &dist2.feet);
  56. printf("Enter inch: ");
  57. scanf("%f", &dist2.inch);
  58.  
  59. add(dist1, dist2, &dist3);
  60.  
  61. /* dist1 এবং dist2 স্ট্রাকচার ভ্যারিয়েবলকে ভ্যালু হিসাবে এবং dist3 স্ট্রাকচার ভ্যারিয়েবলকে রেফারেন্স হিসাবে ফাংশনের মধ্য দিয়ে অতিক্রম(pass) করানো */
  62. printf("\nSum of distances = %d\'-%.1f\"", dist3.feet, dist3.inch);
  63.  
  64. return 0;
  65. }
  66. void add(struct distance d1,struct distance d2, struct distance *d3)
  67. {
  68. // d1 এবং d2 দূরত্বকে যোগ করে d3 এর মধ্যে জমা রাখা
  69. d3->feet = d1.feet + d2.feet;
  70. d3->inch = d1.inch + d2.inch;
  71.  
  72. if (d3->inch >= 12) { /* ইঞ্চির ভ্যালু যদি ১২ থেকে বড় হয় তাহলে ফুটে রূপান্তরিত হবে। */
  73. d3->inch -= 12;
  74. ++d3->feet;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement