๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ ˆํผ๋Ÿฐ์Šค2

ํŒŒ์ด์ฌ ๊นŠ์€ ๋ณต์‚ฌ์™€ ์–•์€ ๋ณต์‚ฌ ๊ฐ์ฒด ์ฐธ์กฐ ํ™•์ธr1 = [1,2,3]r2 = r1r1 is r2 # True(r1๊ณผ r2๊ฐ€ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด๋Š” ๋™์ผํ•œ๊ฐ€?)r1 == r2 # True(r1๊ณผ r2์˜ ๊ฐ’์ด ๊ฐ™์€๊ฐ€?)r1 = [1,2,3]r2 = list(r1)r1 is r2 # False(r1๊ณผ r2๊ฐ€ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด๋Š” ๋™์ผํ•œ๊ฐ€?)r1 == r2 # True(r1๊ณผ r2์˜ ๊ฐ’์ด ๊ฐ™์€๊ฐ€?)์–•์€ ๋ณต์‚ฌ์˜ ๋ฌธ์ œ์ ์„ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.r1 = ['John', ('man', 'USA'), [175, 23]]r2 = list(r1)r2[2][1] += 1 # John์˜ ๋‚˜์ด ํ•œ์‚ด ๋” ๋จน์Œprint(r1)print(r2)# ['John', ('man', 'USA'), [175, 24]]# ['John', ('man', 'USA'), [175.. 2024. 4. 29.
[C++]ํฌ์ธํ„ฐ์™€ ๋ ˆํผ๋Ÿฐ์Šค ์ฐจ์ด C++์—์„œ ํฌ์ธํ„ฐ์™€ ๋ ˆํผ๋Ÿฐ์Šค๋Š” ๋ชจ๋‘ ๋ณ€์ˆ˜๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ฑฐ๋‚˜ ์ฐธ์กฐํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜์ง€๋งŒ, ๊ทธ๋“ค ๊ฐ„์— ์ค‘์š”ํ•œ ์ฐจ์ด์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ •์˜ - ํฌ์ธํ„ฐ(Pointer): ํฌ์ธํ„ฐ๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜์ž…๋‹ˆ๋‹ค. ๋ณ€์ˆ˜์˜ ์ฃผ์†Œ๋ฅผ ์ €์žฅํ•˜๊ณ  ํ•ด๋‹น ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ๊ฐ„์ ‘ ์ฐธ์กฐ๋ฅผ ํ†ตํ•ด ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํฌ์ธํ„ฐ๋Š” '*' ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ ์–ธํ•˜๋ฉฐ, ํ• ๋‹น๋œ ์ฃผ์†Œ๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. - ๋ ˆํผ๋Ÿฐ์Šค(Reference): ๋ ˆํผ๋Ÿฐ์Šค๋Š” ๊ธฐ์กด ๋ณ€์ˆ˜์˜ ๋ณ„์นญ(alias)์ž…๋‹ˆ๋‹ค. ์ฆ‰, ๊ธฐ์กด ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ๋ณ„์นญ์„ ๋งŒ๋“ค์–ด ํ•ด๋‹น ๋ณ€์ˆ˜๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ๋ ˆํผ๋Ÿฐ์Šค๋Š” '&' ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ ์–ธ๋˜๋ฉฐ, ํ•œ ๋ฒˆ ํ• ๋‹น๋˜๋ฉด ๋‹ค๋ฅธ ๋ณ€์ˆ˜๋กœ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์ดˆ๊ธฐํ™” - ํฌ์ธํ„ฐ(Pointer): ํฌ์ธํ„ฐ๋Š” ์ดˆ๊ธฐํ™”ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ ๋„ ํฌ์ธํ„ฐ๋กœ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค... 2023. 1. 9.