728x90

<๋ณ€์ˆ˜ c์— ๋‹ด๊ฒจ์žˆ๋Š” ๊ฐ’๊ณผ ๋ณ€์ˆ˜ a, ๋ณ€์ˆ˜ b์— ๋™์‹œ์— ๋ณต์‚ฌํ•˜๋Š” ๋ฐฉ๋ฒ•>

  • = ์—ฐ์‚ฐ์„ chain ํ˜•์‹์œผ๋กœ ์ ์–ด์ฃผ๋ฉด ๊ฐ€๋Šฅ
  •  a = b = c ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์˜ค๋ฅธ์ชฝ์—์„œ๋ถ€ํ„ฐ ๋จผ์ € b์— ๊ฐ’ c๋ฅผ ๋„ฃ์–ด์ฃผ๊ณ , ๊ทธ๋‹ค์Œ a์— ๊ฐ’ b๋ฅผ ๋„ฃ์–ด์ฃผ๊ฒŒ ๋˜๋ฏ€๋กœ ์ „๋ถ€ c์™€ ๋™์ผํ•œ ๊ฐ’์„ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
#include <stdio.h>

int main() {

	int a = 5, b = 3, c = 9;

	a = b = c;
	printf("A is %d B is %d C is %d", a, b, c);

	return 0;

}

 

โ–ถ๋ฌธ์ œ: ์ •์ˆ˜ a, b, c์— ๊ฐ๊ฐ ๊ฐ’ 1, 2, 3์„ ๋„ฃ๊ณ  c์˜ ๊ฐ’์„ a, b์— ๋ณต์‚ฌํ•œ ๋’ค, a, b, c์˜ ๊ฐ’์„ ์ฐจ๋ก€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด ๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    int a = 1, b = 2, c = 3;
    a = b = c;

    printf("%d %d %d",a,b,c);
    return 0;
}

โ–ถ๋ฌธ์ œ: ์ •์ˆ˜ a, b, c์— ๊ฐ๊ฐ ๊ฐ’ 5, 6, 7์„ ๋„ฃ๊ณ  c์˜ ๊ฐ’์„ a, b์— ๋ณต์‚ฌํ•œ ๋’ค, a, b, c์˜ ๊ฐ’์„ ์ฐจ๋ก€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด ๋ณด์„ธ์š”.

#include <stdio.h>

int main() {
    int a = 5, b = 6, c = 7;
    a = b = c;

    printf("%d %d %d",a,b,c);
    return 0;
}

โ–ถ๋ฌธ์ œ:

์•„๋ž˜์˜ ์ˆœ์„œ๋กœ ์ผ๋“ค์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด ๋ณด์„ธ์š”.

  • ์ •์ˆ˜ a, b, c์— ์ฐจ๋ก€๋Œ€๋กœ ๊ฐ’ 1, 2, 3 ์„ ๋„ฃ์Šต๋‹ˆ๋‹ค.
  • ์„ธ ์ •์ˆ˜์˜ ํ•ฉ์„ ๊ฐ ์ •์ˆ˜ a, b, c์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
  • a, b, c์˜ ๊ฐ’์„ ์ฐจ๋ก€๋กœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
#include <stdio.h>

int main() {
    int a = 1, b = 2, c = 3;
    int d = a+b+c;
    a = b = c = d;

    printf("%d %d %d",a,b,c);
    return 0;
}

 

+ Recent posts