|
![](/images/resource/spacer.gif) |
สอบถามเรื่องการเขียนฟังชั่น pass by value หน่อยครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ผมต้องการส่งค่าตัวแปร โครงสร้าง s1 กับ s2 ไปในฟังชั่น Swap ครับเพื่อไปสลับค่ากัน ในฟังชัน Swap ต้องเขียนยังไงและ พารามิเตอร์เขียนยังไงขอบคุณครับ
Code (C#)
#include <stdio.h>
#include <conio.h>
struct Data{
int x,y;
}s1,s2;
void Swap( ){
}
int main(){
s1.x = 3; s1.y=3; s2.x=5; s2.y=5;
printf("Before swap s1.x = %d, s1.y = %d \n",s1.x,s1.y);
printf("After swap s2.x = %d, s2.y = %d \n",s2.x,s2.y);
Swap(Data *s1,Data *s2);
printf("Before swap s1.x = %d, s1.y = %d \n",s1.x,s1.y);
printf("After swap s2.x = %d, s2.y = %d ",s2.x,s2.y);
getch();
}
Tag : C
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-12-02 10:50:59 |
By :
Hawxeye |
View :
2001 |
Reply :
1 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
By value, is temp value, not affect to its original variables.
|
ประวัติการแก้ไข 2020-06-06 19:10:05
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2020-06-06 19:09:44 |
By :
PhrayaDev |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
Load balance : Server 04
|