¹è¿ call-by-value¿Í call-by-reference¸¦ µ¿½Ã¿¡ °¡´ÉÇÑ°¡¿ä
ÇÑŵ¿ 2009-11 2009-11-18 02:12:18 Á¶È¸ 16438 Ãßõ 0
¹è¿¿¡ ÀÖ´Â ¼öÄ¡ µ¥ÀÌÅ͸¦ °øÀ¯Çϸé¼, ÇÔ¼ö¿¡¼ ÀϺΠº¯°æÇؼ »ç¿ëÇϽô°ųª ¹Í½º ¿ëµµ½Ã¶ó¸é,
¸ÞÀÎ ÇÑÂÊ¿¡¼¸¸ °ªÀ» ÀÏÁ¤ÇÏ°Ô À¯Áö°ü¸®ÇÏ°í, º¹»çº»À¸·Î ¸¸µé¾î ÇÔ¼ö·Î ³¯¸®½Ã¸é µÇÁö ¾ÊÀ»±î¿©?
ÇãÁ¢ÄÚµå ¿Ã·Áº¾´Ï´Ù.
~~~
#include <stdio.h>
#include <string.h>
void calc_func(int *pa);
int main()
{
int a[5]={'\0'};
static int org[5]={100,200,300,400,500};
//memset(a, '\0', sizeof (a));
memcpy(a, org, sizeof(org));
calc_func(a);
printf("ORG:[%d, %d, %d, %d, %d] \n", org[0], org[1], org[2], org[3], org[4]);
printf("CHG:[%d, %d, %d, %d, %d] \n", a[0], a[1], a[2], a[3], a[4]);
printf("MIX:[%d, %d, %d, %d, %d] \n", org[0], a[1], org[2], a[3], org[4]);
return 0;
}
void calc_func(int *pa)
{
pa[0] = 999;
// ~~
//pa[4] = 888;
//printf("[%d, %d, %d, %d, %d] changed...\n", pa[0], pa[1], pa[2], pa[3], pa[4]);
}
Output :
ORG:[100, 200, 300, 400, 500]
CHG:[999, 200, 300, 400, 500]
MIX:[100, 200, 300, 400, 500]
structure ³ª class ¿¡ ³Ö°í ±× structure ³ª class ¸¦ ÇÔ¼ö ÀÎÀÚ·Î Àü´ÞÇÏ½Ã¸é µË´Ï´Ù.
http://www.ibm.com/developerworks/kr/library/l-rt3/
ÀÌ·²¶© cbv °í Àú·²¶© cbr À̶ó¸é ...
·¹ÆÛ·±½ºÀÎÁö º§·ùÀÎÁöÀÇ °ªÀ» °¡Áö´Â ¶ÈµüÀÌ ½ºÀ§Ä¡ º¯¼ö¸¦ Çϳª °¡Áö´Â .. ½ºÆ®·°Ãĸ¦ ¾²½Ã¸é µÇÁö ¾ÊÀ»±î¿æ?