profile-img
์ง€๋ฐ์ด์˜ ํ‹ฐ์Šคํ† ๋ฆฌ
images/slide-image
๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ + 28
list_img
[C++] STL ์—ฐ๊ด€์ปจํ…Œ์ด๋„ˆ STL Associative Container (sets and multisets, maps and multimaps)
user-img ์ฐœ๋‹
2024.03.29
ใ…Žใ…Ž ์—ฐ๊ด€ ์ปจํ…Œ์ด๋„ˆ Associative Container automatically sorted ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋จ ( ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์ด์ฆˆ๊ฐ€ 0์ธ set์ด ๋งŒ๋“ค์–ด์ง ๋ณต์‚ฌ์ƒ์„ฑ์ž copy constructor set set3(set1); set set4 = set1; ์ดˆ๊ธฐํ™” ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ์ž initializer list constructor set set5 = {10, 30, 20}; //Elements will be stored in ascending order ๋ฒ”์œ„ ์ƒ์„ฑ์ž Range constructor set::iterator iter = set3.begin(); ++iter; // ๋˜๋Š” auto iter = set3.begin()์œผ๋กœ ์จ๋„๋จ set set4(iter, set3.end()); // set4..
list_img
[C++] STL ์ˆœ์ฐจ ์ปจํ…Œ์ด๋„ˆ STL Sequence Container (Vector, List)
user-img ์ฐœ๋‹
2024.03.29
๋“œ๋””์–ด ์ปจํ…Œ์ด๋„ˆ ์ฑ•ํ„ฐ๋กœ ๋„˜์–ด๊ฐ„๋‹ค !! STL Sequence Container์€ ๊ฐ์ฒด๋ฅผ sequential oreder (์ˆœ์ฐจ์ ) ์œผ๋กœ ์ €์žฅํ•˜๋Š” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ์ด๋‹ค Sequence Containers Type of Iterator Supported description vector (implemented as a dynamic array) Random Access ๋™์  ๋ฐฐ์—ด๋กœ ๊ตฌํ˜„๋œ ์ž๋ฃŒ๊ตฌ์กฐ, ๋ฐฐ์—ด๊ณผ ์œ ์‚ฌํ•œ ์„ ํ˜•๊ตฌ์กฐ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์—ฐ์†์ ์œผ๋กœ ์ €์žฅํ•˜์—ฌ ๋™์ ์œผ๋กœ ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ์Œ. ๋ฐ์ดํ„ฐ ์‚ฝ์ž…, ์‚ญ์ œ๊ฐ€ ์žฆ์€ ๊ฒฝ์šฐ์—๋Š” ์ ์ ˆํ•˜์ง€ ์•Š์Œ. list (implemented as a doubly-linked list) Bidirectional ์ด์ค‘ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ๋กœ ๊ตฌํ˜„๋œ ์ž๋ฃŒ๊ตฌ์กฐ, ๊ฐ ์š”์†Œ๊ฐ€ ์ด์ „ ์š”์†Œ์™€ ๋‹ค์Œ ์š”์†Œ์˜ ์ฃผ์†Œ..
list_img
[C++] ostream iterator ์ถœ๋ ฅ์ŠคํŠธ๋ฆผ ๋ฐ˜๋ณต์ž + etc...
user-img ์ฐœ๋‹
2024.03.29
์šฐ์„  ํ—ค๋”์— #include ๋„ฃ๋Š”๊ฑฐ๋ฅผ ๊นŒ๋จน์ง€ ๋ง์ž! ostream_iterator๋Š” ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ ๋ฐ˜๋ณต์ž๋กœ, ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์›์†Œ์˜ ํƒ€์ž…์„ ๋ฐ›๋Š” ํด๋ž˜์Šค ํ…œํ”Œ๋ฆฟ์ž…๋‹ˆ๋‹ค. ์ƒ์„ฑ์ž๋Š” ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ๊ณผ ์ด ์ŠคํŠธ๋ฆผ์˜ ์›์†Œ ๋๋งˆ๋‹ค ๋ถ™์ผ string ํƒ€์ž…์˜ ๊ตฌ๋ถ„์ž๋ฅผ ์ธ์ˆ˜๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. ostream_iterator ํด๋ž˜์Šค๋Š” ์ŠคํŠธ๋ฆผ์— ์›์†Œ๋ฅผ ์“ธ ๋•Œ operator
list_img
[C++] Cycling Iterators ์ˆœํ™˜ ๋ฐ˜๋ณต์ž
user-img ์ฐœ๋‹
2024.03.29
~ ์ˆœํ™˜ ๋ฐ˜๋ณต์ž ~ for ๋ฌธ๊ณผ while๋ฌธ์œผ๋กœ ์‹ธ์ดํด์„ ๋Œ๋ ค๋ณด์•„์š”.. vector v = {1, 2, 5, 7, 8}; vector const_iterator iter = v.cbegin(); vector const_iterator iterEnd = v.cend(); for(iter; iter != iterEnd; ++iter) //NULLPTR๊ฐ€ ์•„๋‹๋•Œ๊นŒ์ง€ ์‹ธ์ดํด { cout
list_img
[C++] iterator's function
user-img ์ฐœ๋‹
2024.03.29
1. begin() vector v = { 10, 20, 30, 40, 50, 60 }; cout
list_img
[C++] STL์˜ ๋ฐ˜๋ณต์ž (Iterators)
user-img ์ฐœ๋‹
2024.03.28
~ Container๋ฅผ ์‚ดํŽด๋ณด๊ธฐ ์ „์— Iterator๋ฅผ ์‚ดํŽด๋ด…์‹œ๋‹ค ~ Container classes make an intensive use of iterators to .... 1. ์ปจํ…Œ์ด๋„ˆ์— ๋“ค์–ด๊ฐ€๋Š” ๋ฐ์ดํ„ฐ๋“ค์˜ ์ˆœํ™˜์„ ๋„์›€ 2. ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ๋“ค์—๊ฒŒ ๋™์ผํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณต (provide uniform interface) 3. ๋ฐ˜๋ณต์ž๋Š” ํฌ์ธํ„ฐ์˜ "์ผ๋ฐ˜ํ™” ๋œ ๊ฐœ๋…"์ด๋‹ค. -> ํฌ์ธํ„ฐ๋Š” ์•„๋‹˜! ์ถ”์ƒํ™”๋œ ๊ฐœ๋…! (A generalization of a pointer) 4. An iterator variable points to one data entry in the container 5. Each container has its "own" iterator type -> ๋ฐ์ดํ„ฐํƒ€์ž… ๋“ค์ด ๊ทธ๋“ค๋งŒ์˜ ๋ฐ˜๋ณต์ž..
list_img
[C++] STL์ด๋ž€? ( STL์˜ ์ •์˜์™€ ๊ตฌ์„ฑ์š”์†Œ)
user-img ์ฐœ๋‹
2024.03.27
- Standard Template Library (STL) : library of classes and associated functions - ํ•œ๊ตญ์–ด๋กœ๋Š” ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ผ๊ณ  ํ•œ๋‹ค. - template-based components ๋ฅผ ํ†ตํ•ด software reuse์„ ํ•จ. -> ์ด๋Š” ํƒ€์ž…์˜ ์ผ๋ฐ˜ํ™”๋กœ ๋งํ•  ์ˆ˜์žˆ์Œ : which is "GENERIC PROGRAMMING ! " ( vs functional programming - ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ) 1. Containers : ์ปจํ…Œ์ด๋„ˆ - Data structures capable of storing objects of almost any data type (there are some restrictions) - ํ”ํžˆ stl ์ž๋ฃŒ๊ตฌ์กฐ๋ผ๋Š” ..
list_img
Sep W4 | .. ์ƒํ™œ์ผ๋ณธ์–ด ๋‘๊ฐœ ใ…Žใ…Ž
user-img ์ฐœ๋‹
2023.09.22
ใ„ใคใ‚ตใƒƒใƒผใ‚ซใƒผใ‚„ใฃใฆใ‚‹ใฎ๏ผŸ ๏ผš ์ถ•๊ตฌ ์–ธ์ œํ•ด ?? .. ์‚ฌ์‹ค ๋„˜ ์‰ฌ์šด ์ผ๋ณธ์–ด๋ผ ํ•œ๋ฒˆ์— ์•Œ์•„๋“ค์—ˆ๋”ฐ ๊ทธ์น˜๋งŒ ์ƒˆ๋กœ์šด ์‚ฌ์‹ค 1. ์ด์ธ  ์‚ฌ์นด์–๋–ผ๋ฃจ๋…ธ? ๋„ ํ• ์ˆ˜ ์žˆ์ง€๋งŒ 2. ์‚ฌ์นด ์ด์ธ  ์–๋–ผ๋ฃจ๋…ธ?? ๋„ ํ• ์Šˆ์žˆ๋‹น ใ…Žใ……ใ…Ž ใ„ใค๋Š” ใ„ใคใ‚‚ใชใ‚“ใฉใงใ‚‚(์–ธ์ œ๋‚˜ ๋ช‡๋ฒˆ์ด๋ผ๋„) ์—์„œ์ฒ˜๋Ÿผ ์–ธ์ œ? .. ์ž„ ใ‚„ใฃใฆใ‚‹ ๋Š” ์•ผ๋ฃจ (~ํ•˜๋‹ค?) ์˜ ์˜๋ฌธ + ์ง„ํ–‰ํ˜• ์ธ๋ฐ ์—ฌ๊ธฐ์„œ ์ถ•๊ตฌ๋ฅผ ํ•˜๋‹ค๋Š” ใ‚ตใƒƒใƒผใ‚ซใƒผใ‚’ใ‚„ใ‚‹ใ€‚๋ผ๊ตฌ ์ƒ๊ฐํ• ์ˆ˜ ์žˆ์ง€๋งŒ ์‚ฌ์นด๋Š” ์Šค๋ฃจ๋‹ค .. ์ถ•๊ตฌ์–ด๋””์„œ ํ• ๊บผ์•ผ๋Š” : ์‚ฌ์นด ๋„์ฝ”๋ฐ ์Šค๋ฃจ๋…ธ? ์‚ฌ์นด ๋„์ฝ”๋‹ˆ ์Šค๋ฃจ๋…ธ?? ์ •๋„๊ฐ€ ๋ ๊ฑฐ๊ฐ™๋‹ค(๊ณ  ์ƒ๊ฐํ•œ๋‹น.....) ๋ฐ ๋‹ˆ ๋Š” ์•„์ง๋„ ๊ตฌ๋ถ„ ๋ชจ๋‹จ๋‹ค . ๊ทผ๋ฐ ๋˜ ์•ผ๋ฃจ๊ฐ€ ๋ญ๋ƒ๊ตฌ ํ•˜๋ฉด ์ข€ ๊ณค๋ž€ํ•ด์ง€๋Š”๋ฐ ์™œ๋ƒ๋ฉด ์ผ๋‹จ ๋‚ด๊ฐ€ ์ƒ๊ฐํ–ˆ์„๋•Œ๋Š” ์ „ํ˜€ ์™€๋‹ฟ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค .. ๋‚˜์˜ ์งง์€ ์ผ๋ณธ์–ดํšŒํ™” ์•Œ์•„๋“ฃ๊ธฐ ๋Šฅ๋ ฅ์œผ๋กœ๋Š” ... ์•ผ๋ฃจ -> ..
list_img
[C++] ์ด๋ก ๊ณต๋ถ€ ์˜ค๋‹ต๋…ธํŠธ 1
user-img ์ฐœ๋‹
2023.09.22
## Assuming that you are not implementing a portion of the standard library, which of these are legal identifiers. (This means that they follow the syntax rules for C++) - switch - _int - string what is L-Value, R-Value or Non-Modifiable L-Value. ??? In C++ and many other programming languages, the terms "L-value" and "R-value" are used to classify expressions based on whether they can appear on..
list_img
[C++] Introduction to C++ Syntax & Variables
user-img ์ฐœ๋‹
2023.09.22
์ด ์•„์ด์˜ ํŠน์ง• .. 1. native code 2. machine language 3. machine dependent This code is written in machine (and assembly) language for a specific processor; thus it is non-portable or machine dependent. This is the native code for the 6502 processor. Machine language is both difficult to write and to understand. (That's why Woz added all of the comments on the right). step 1 - text editor : vim ๊ฐ™์€๊ฑฐ ! ์ฒ˜..

ใ…Žใ…Ž 

 

์—ฐ๊ด€ ์ปจํ…Œ์ด๋„ˆ Associative Container

automatically sorted
์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋จ (<)

 


Sets and Multisets

  • automatically sorted ( By default, in ascending order)
  • multisets์€ ์ค‘๋ณตํ—ˆ์šฉ, sets๋Š” ํ—ˆ์šฉ ์•ˆํ•จ !

๊ธฐ๋ณธ์ƒ์„ฑ์ž default constructor

set<int> set1;
set1.insert(6);
set1.insert(2);
set1.insert(4);  // set is: 2 4 6

-> ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์ด์ฆˆ๊ฐ€ 0์ธ set์ด ๋งŒ๋“ค์–ด์ง

๋ณต์‚ฌ์ƒ์„ฑ์ž copy constructor

set<int> set3(set1);
set<int> set4 = set1;


์ดˆ๊ธฐํ™” ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ์ž initializer list constructor

set<int> set5 = {10, 30, 20};
//Elements will be stored in ascending order


๋ฒ”์œ„ ์ƒ์„ฑ์ž Range constructor

set<int>::iterator iter = set3.begin(); ++iter;
// ๋˜๋Š” auto iter = set3.begin()์œผ๋กœ ์จ๋„๋จ
set<int> set4(iter, set3.end());
// set4 is: 20 30 40

 

set::erase(value)

size_type erase(const value_type& val);
// erase() ํ•จ์ˆ˜๋Š” ์‚ญ์ œ๋œ ์š”์†Œ์˜ ๊ฐฏ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•จ! 

multiset<int> aMultiSet =
{ 14, 12, 13, 17, 14, 19, 18, 16, 14, 14, 19, 11, 15 };
size_t itemsDeleted = aMultiSet.erase(14);
cout << itemsDeleted << "\n"; //4, ์‚ญ์ œ๋œ 14์˜ ๊ฐฏ์ˆ˜
for (auto elem : aMultiSet) cout << elem << " "; // 11 12 13 15 16 17 18 19 19

 

set::erase(position)

iterator erase(const_iterator position);

multiset<int> aMultiset = { 11, 12, 13, 15, 17 };
auto iterSet = ++aMultiset.begin(); 
cout << *iterSet << endl; //12

iterSet = aMultiset.erase(iterSet); //-> ์‚ญ์ œ๋œ ์š”์†Œ์˜ ๋‹ค์Œ์š”์†Œ๋ฅผ ๊ฐ€๋ฅดํ‚ด
cout << *iterSet << endl; // 13

for(auto elem : aMultiSet) 
	cout << elem << endl; // 11 13 15 17

 

set::erase(range)

iterator erase(const_iterator first, const_iterator last);

set<int> aSet = {11, 12, 13, 15, 17, 18, 19};

auto iterSet = aSet.begin();
for (int i = 1; i < 6; ++i) 
{
	++iterSet; //5๋ฒˆ๋ฐ˜๋ณต 
}
cout << *iterSet << endl; // 18 (6th element)

iterSet = aSet.erase(++aSet.begin(), iterSet); // 12 ~ 18 ์‚ฌ์ด์— ์žˆ๋Š”๊ฑฐ ๋‹ค์ง€์›€ 
cout << *iterSet << endl; // 18(์‚ญ์ œ๋œ ์š”์†Œ ๋’ค์— ์žˆ๋Š” ๋ฐ”๋กœ ์ฒซ ์š”์†Œ

for(auto elem:aSet)
	cout << elem << endl; // 11 18 19

-> ์™œ ๋งˆ์ง€๋ง‰์ด 11 12 18 19 ๊ฐ€ ์•„๋‹ˆ์ง€?? 

set::find(value)

set<int> aSet = { 23, 34, 48, 57, 68, 71, 83 };
auto iter = aSet.find(57); //iter์€ 57์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ฐ˜๋ณต์ž๊ฐ€๋จ 

if (iter != aSet.end())
cout << "Element found."; // set์—์„œ 57์„ ์ฐพ์œผ๋ฉด ์ถœ๋ ฅ !
else
cout << "Element not found.";

 

* find ํ•จ์ˆ˜๋Š” True and False, Boolean Value๋กœ ๋ฆฌํ„ดํ•  ์ˆ˜ ์—†๋‹ค ! 

 


Maps and Multimaps

  • elements๋ฅผ key/value์Œ์˜ ํ˜•ํƒœ๋กœ ๊ด€๋ฆฌํ•จ 
  • automatically sorted ( By default, in ascending order)
  • multimaps์€ ์ค‘๋ณตํ—ˆ์šฉ, maps๋Š” ํ—ˆ์šฉ ์•ˆํ•จ !
 

 

์ดˆ๊ธฐํ™” ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ์ž initializer list constructor

-> When data is immediately available !! 

map<int, string> aMap = {{1, "one"}, {2, "two"}, {3, "three"}, {4, "four"}};

auto iterEnd = aMap.cend();
for (auto iter = aMap.cbegin(); iter != iterEnd; ++iter)
cout << iter->first << " " << iter->second << "\n";

 

 

๊ธฐ๋ณธ์ƒ์„ฑ์ž์™€ ๋Œ€๊ด„ํ˜ธ(?) Default Constructor + Subscript

-> When data is NOT immediately available !!

map<char, int> aMap;
aMap['A'] = 90;
aMap['b'] = 80;
aMap['C'] = 70;
aMap['D'] = 60;

auto iterEnd = aMap.cend();
for (auto iter = aMap.cbegin(); iter != iterEnd; ++iter)
cout << iter->first << " " << iter->second << "\n";

// Output : A 90, C 70, D 60, b 80
// ASCII code ์— ๋”ฐ๋ผ์„œ b 80์ด ๋’ค๋กœ ๊ฐ

 

๊ธฐ๋ณธ์ƒ์„ฑ์ž Default Constructor + map::insert

-> insert / make_pair ์‚ฌ์šฉ !!

map<int, int> intMap;

for (int i = 1; i < 10; ++i) // insert integers
intMap.insert (make_pair (i, (100 / i)));

auto itEnd = intMap.cend();
for (auto it = intMap.cbegin(); it != itEnd; ++it)
cout << it->first << " " << it->second << "\n";

// map is: {(1,100),(2,50),(3,33),...(8,12),(9,11)}

 

map::find(value)

const_iterator find(const value_type& k) const;
map<string, int> states = {{"AK", 1959}, {"CA", 1850}, {"FL", 1845}, {"IL", 1818}, {"IO", 1846}, {"OR", 1859}};

auto iter = states.find("CA");
if (iter != states.end())
	cout << "Year: " << iter->second;
else
	cout << "State not found.";

 

 

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

๋“œ๋””์–ด ์ปจํ…Œ์ด๋„ˆ ์ฑ•ํ„ฐ๋กœ ๋„˜์–ด๊ฐ„๋‹ค !!

STL Sequence Container์€ ๊ฐ์ฒด๋ฅผ sequential oreder (์ˆœ์ฐจ์ ) ์œผ๋กœ ์ €์žฅํ•˜๋Š” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ์ด๋‹ค

 

Sequence Containers Type of Iterator Supported description
vector (implemented as a dynamic array) Random Access ๋™์  ๋ฐฐ์—ด๋กœ ๊ตฌํ˜„๋œ ์ž๋ฃŒ๊ตฌ์กฐ, ๋ฐฐ์—ด๊ณผ ์œ ์‚ฌํ•œ ์„ ํ˜•๊ตฌ์กฐ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์—ฐ์†์ ์œผ๋กœ ์ €์žฅํ•˜์—ฌ ๋™์ ์œผ๋กœ ํฌ๊ธฐ๋ฅผ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ์Œ. ๋ฐ์ดํ„ฐ ์‚ฝ์ž…, ์‚ญ์ œ๊ฐ€ ์žฆ์€ ๊ฒฝ์šฐ์—๋Š” ์ ์ ˆํ•˜์ง€ ์•Š์Œ.
list (implemented as a doubly-linked list) Bidirectional ์ด์ค‘ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ๋กœ ๊ตฌํ˜„๋œ ์ž๋ฃŒ๊ตฌ์กฐ, ๊ฐ ์š”์†Œ๊ฐ€ ์ด์ „ ์š”์†Œ์™€ ๋‹ค์Œ ์š”์†Œ์˜ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ์ €์žฅํ•จ. ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ์‚ญ์ œ๊ฐ€ ์žฆ์„ ๊ฒฝ์šฐ์—๋Š” ๋น ๋ฅธ ์„ฑ๋Šฅ์„ ๋ณด์ด์ง€๋งŒ, ์ž„์˜์˜ ์œ„์น˜์— ์žˆ๋Š” ์š”์†Œ์— ์ ‘๊ทผํ• ๋•Œ๋Š” ํšจ์šฉ์„ฑ์ด ๋–จ์–ด์ง. 

 

* Random Access : ๋ฐฐ์—ด์˜ ์š”์†Œ๋ฅผ ์ž„์˜์˜ ์œ„์น˜์—์„œ ์ง์ ‘ ์•ก์„ธ์Šค ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ 

-> ์ธ๋ฑ์Šค ์—ฐ์‚ฐ์ž(sunscript operator) ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐ์—ด์˜ ํŠน์ •์š”์†Œ์— ์•ก์„ธ์Šค : array[i]


vector container

  • implemented as a dynamic array : ๋™์ ๋ฐฐ์—ด๋กœ ๊ตฌํ˜„๋จ. array์™€ ์œ ์‚ฌํ•˜๊ฒŒ ์—ฐ์†์ ์ธ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์— ์š”์†Œ๋ฅผ ์ €์žฅํ•˜๊ณ  ํ•„์š”์— ๋”ฐ๋ผ ํฌ๊ธฐ๋ฅผ ๋™์ ์œผ๋กœ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ์Œ.
  • can access elements randomly (์ž„์˜์ ์œผ๋กœ ์ ‘๊ทผ)
  • ๊ธฐ๋ณธ์ƒ์„ฑ์ž(default constructor)์ด์™ธ์—๋„ ๋‹ค์–‘ํ•œ ์ƒ์„ฑ์ž๋ฅผ ํฌํ•จ -> ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ vector์„ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  ์ƒ์„ฑ๊ฐ€๋Šฅ
  • size -> number of elements / capcity -> how much memeory is allocated to contain elements.

๊ธฐ๋ณธ ์ƒ์„ฑ์ž default constructor

.reserve()

vector<int> vector1; //capacity = 0
vector1.reserve(20);
//reserve() sets an initial capacity for the vector = 20
vector1.push_back(10); //capacity = 1
vector1.push_back(20); //capacity = 2

 

 

๋ณต์‚ฌ ์ƒ์„ฑ์ž copy constructor

vector<int> vector2(vector1);
vector<int> vector3 = vector1;

 

์ดˆ๊ธฐํ™” ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ์ž initializer list constructor

vector<int> vector4{ 130, 750, 259, 1234};
vector<int> vector5 = {234, 54, 5634, 65};
// set size and capacity right away + with specific elements!!

 

๋ฒ”์œ„ ์ƒ์„ฑ์ž Range constructor

vector<int> vector5 {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
vector<int> vector6 (vector5.begin() + 2, vector5.begin() +6);
//vector6 becomes : 30 40 50 60
  • (20, 50) "closed range" => 20 30 40 50 
  • [20, 50] "open range" => 30 40 
  • [20, 50) "half open range" => 30 40 50

vector capacity 

  • vector grows automatically; by default their capacity is increased as needed
  • tho do not shrink automatically; maintain the same capacity 
#include <iostream>
#include <vector>

int main() {
    std::vector<int> vec; 
    
    std::cout << "Initial capacity: " << vec.capacity() << std::endl;
    
    for (int i = 0; i < 10; ++i) 
    {
        vec.push_back(i); //vector capacity automatically grows
        std::cout << "Size: " << vec.size() << ", Capacity: " << vec.capacity() << std::endl;
    }
    
    return 0;
}

 

elements๋ฅผ ์ €์žฅํ•  ๊ณต๊ฐ„์ด ์—†์„๊ฒฝ์šฐ... -> ๋™์ ๋ฐฐ์—ด์ด ์ƒ์„ฑ (dynamic array) -> ๋ชจ๋“  elements๊ฐ€ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์— ๋ณต์‚ฌ๋จ

 

Inserting Elements

iterator insert(const_iterator position, cosnt value_type& val);
		//๋„ฃ๊ณ ์‹ถ์€ position, ๋„ฃ๊ณ ์‹ถ์€ single element
iterator insert(const_iterator position, size_type n, const value_type& val);
		//๋„ฃ๊ณ ์‹ถ์€ position, ๋„ฃ๊ณ ์‹ถ์€ ํšŸ์ˆ˜, ๋„ฃ๊ณ ์‹ถ์€ single element
iterator insert(const_iterator position, initializer_list<value_type> il);
		//๋„ฃ๊ณ ์‹ถ์€ position, ๋„ฃ๊ณ ์‹ถ์€ initializer list object

vector<int> vector1 = {10, 20, 30, 40};
vector1.insert(vector1.begin() + 2, 100); // 10 20 100 30 40
vector1.insert(vector1.begin() + 2, 3, 100); // 10 20 100 100 100 30 40 
vector1.insert(vector1.begin() + 2, {1, 2, 3, 4}); // 10 20 1 2 3 4 30 40

 

Subscript Operator ์ฒจ์ž ์—ฐ์‚ฐ์ž 

vector<int> vector1 = {1, 2, 3, 4, 5};
vector1[2] = 999;

//vector1 is 1 2 999 4 5

 

Other STL vector functions

front() / back() / begin() / end() / erase() / pop_back() 

vector<string> names = { "Ted", "Sue", "Bob", "Jill"};
// Return the first element.(/= .begin())
cout << names.front() << "\n"; //Ted
// Return the last element.(/= .end())
cout << names.back() << "\n"; //Jill 
// Delete "Bob".
names.erase(names.begin() + 2); // vector is: Ted Sue Jill
// Delete the last element.(which is Jill)
names.pop_back(); // vector is: Ted Sue

list container

  • implemented as a doubly-linked list : ์ด์ค‘์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ๋กœ ๊ตฌํ˜„๋จ. ์ด๋Š” ์—ฐ์†์ ์ธ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์— ์š”์†Œ๋ฅผ ์ €์žฅํ•˜์ง€์•Š๋Š”๋‹ค๋Š” ๋ง๊ณผ ๊ฐ™์Œ.. ->  ๋ฆฌ์ŠคํŠธ์˜ ๊ฐ์š”์†Œ๋Š” ๋‹ค์Œ ์š”์†Œ๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ, ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐํ• ๋•Œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์žฌํ• ๋‹น ํ•  ํ•„์š”๊ฐ€ ์—†์Œ. ๋”ฐ๋ผ์„œ ๋ฆฌ์ŠคํŠธ๋Š” ๋™์ ์œผ๋กœ ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•˜๋Š”๋ฐ์— ํšจ์œจ์ ์ด๋‹ค. 
  • has no random access (์ž„์˜์ ์œผ๋กœ ์ ‘๊ทผ ๋ถˆ๊ฐ€๋Šฅ!!!!) -> ++iter, --iter ์€ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ (iter +2) ๋Š” ๋ถˆ๊ฐ€๋Šฅ!!!!
  • ์ฒจ์ž ์—ฐ์‚ฐ์ž ์‚ฌ์šฉ๋ถˆ๊ฐ€ ! (subscript operator) 
  • slist(singly-linked-list) ๋„ ์กด์žฌํ•จ ใ…Ž

๊ธฐ๋ณธ ์ƒ์„ฑ์ž default constructor

* By default, an empty list will be created of size 0.

list<int> list1;
list1.push_back(10);
list1.push_back(80);
list1.push_back(54); // list is now: 10 80 54
list1.push_front(3);
list1.push_front(9); // list is now: 9 3 54 80 10

๋ณต์‚ฌ ์ƒ์„ฑ์ž copy constructor

list<int> list2(list1); //list1์ด ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌ๋œ list2์ƒ์„ฑ
list<int> list3 = list1;

์ดˆ๊ธฐํ™” ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ์ž initializer list constructor

list<int> list4{ 130, 750, 259, 1234};
list<int> list5 = {234, 54, 5634, 65};
// set size and capacity right away + with specific elements!!

 

๋ฒ”์œ„ ์ƒ์„ฑ์ž Range constructor

list<int> list5 {10, 20, 30, 40};
list<int>::iterator iter = list5.begin();
++iter;
++iter;

list<int> list6(iter, list5.end());

//list6 contains : 30 40 
//list cannot use list5.begin() + 2!!!! ์ž„์˜์  ์ ‘๊ทผ ๋ถˆ๊ฐ€๋Šฅ!

 

For loop to Increment

list<int> aList = { 1, 2, 3, 4, 5, 6, 7, 8 };
auto iter = aList.begin(); // iter์€ 1
for (int i = 0; i < 6; ++i) // ์ด 6 ๋ฒˆ ๋ฐ˜๋ณต 
	++iter; // 1์—์„œ ์‹œ์ž‘ํ•ด์„œ 2 3 4 5 6 7 (6๋ฒˆ๋ฐ˜๋ณต) 
cout << *iter; // will print 7

 

Transferring elements

list::splice()

void splice(const_iterator position, list& x);
void splice(const_iterator position, list& x, const_iterator first, const_iterator last);

list<int> nums1 = { 5, 4, 3, 2, 1};
list<int> nums2 = { 77, 66, 55}; 
nums1.splice(++nums1.begin(), nums2); //nums1 is : 5 77 66 55 4 3 2 1 , num2 is empty
nums1.splice(nums1.begin(), ++nums2.begin(), nums2.end()); //nums1 is : 66 55 5 4 3 2 1 , nums2 is 77

Merging lists

void sort();
void merge(list& x);

list<int> nums5 = { 1, 7, 3, 4, 5};
list<int> nums6 = { 999, 888, 777};
list<int> nums7 = { 89, 23, 874};
nums5.sort(); // nums5 is : 1 3 4 5 7
nums6.sort(); // nums6 is : 777 888 999
nums5.merge(nums6) // nums5 is : 1 3 4 5 7 777 888 999, num6 is empty

//what happens if we do not sort the list? 
nums7.merge(nums6); // nums7 is : ...์กธ๋ผ ๋ณต์žกํ•ด์ง. ๊ทธ๋ƒฅ sortํ•˜์ž ใ…Ž

Other STL list functions

push_front() / pop_front() / reverse() / sort() / remove() 

list<int> scores = { 24, 76, 99, 87 };
// Add a new element to the front.
scores.push_front(75); // list is: 75 24 76 99 87
// Delete the front element.
scores.pop_front(); // list is: 24 76 99 87
// Reverse the order of elements.
scores.reverse(); // list is: 87 99 76 24
// Sort the list.
scores.sort(); // list is: 24 76 87 99
// Delete a given element in the list.
scores.remove(87); // list is: 24 76 99

 


Returning Iterators

std::vector::erase
iterator erase(const_iterator position);

vector<int> v = {1, 4, 5, 2, 3};
v.erase(v.begin() + 3;); // v is : 1 4 5 3

vector<int> v = {1, 4, 5, 2, 3};
vector<int>::iterator iter = v.erase(v.begin() + 3); 
	/* ๋จผ์ € v.begin() + 3์„ ํ†ตํ•ด ์ธ๋ฑ์Šค๊ฐ€ 3์ธ ์š”์†Œ์— ๋Œ€ํ•œ ๋ฐ˜๋ณต์ž๋ฅผ ์–ป๊ณ , 
   	 v.erase() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๋‹น ์š”์†Œ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. 
   	 ์ด ๋ฐ˜๋ณต์ž๋Š” ์‚ญ์ œ๋œ ์š”์†Œ์˜ ์œ„์น˜๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. */
v.insert(iter, 100); // v is : 1 4 5 100 3

 

Q. iter์ด ์ธ๋ฑ์Šค๊ฐ€ 3์ธ ์š”์†Œ์— ๋Œ€ํ•œ ๋ฐ˜๋ณต์ž๋ฅผ ์–ป๊ณ , ๊ทธ๊ฑธ ์‚ญ์ œํ•จ. ๊ทธ๋Ÿผ ์œ„์น˜๊ฐ’(position)์„ ๊ธฐ๋กํ•˜๊ณ , ๊ทธ  value๋Š”nullptr ์ด ๋˜๋Š”๊ฑด๊ฐ€?? 

A. 

 

๋— ! ์–ด๋ ต๋‹ค .. 

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

์šฐ์„  ํ—ค๋”์— #include <iterator> ๋„ฃ๋Š”๊ฑฐ๋ฅผ ๊นŒ๋จน์ง€ ๋ง์ž!

 

ostream_iterator๋Š” ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ ๋ฐ˜๋ณต์ž๋กœ, ํƒ€์ž… ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์›์†Œ์˜ ํƒ€์ž…์„ ๋ฐ›๋Š” ํด๋ž˜์Šค ํ…œํ”Œ๋ฆฟ์ž…๋‹ˆ๋‹ค. ์ƒ์„ฑ์ž๋Š” ์ถœ๋ ฅ ์ŠคํŠธ๋ฆผ๊ณผ ์ด ์ŠคํŠธ๋ฆผ์˜ ์›์†Œ ๋๋งˆ๋‹ค ๋ถ™์ผ string ํƒ€์ž…์˜ ๊ตฌ๋ถ„์ž๋ฅผ ์ธ์ˆ˜๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. ostream_iterator ํด๋ž˜์Šค๋Š” ์ŠคํŠธ๋ฆผ์— ์›์†Œ๋ฅผ ์“ธ ๋•Œ operator<<๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

- Used to output data to an output stream 

ostream_iterator<Tyoe> out(ostream&);

 

์˜ˆ์‹œ:

#include <iterator>
...
ostream_iterator<char> screen1(cout);
copy(v.begin(), v.end(), screen1);
	//will output the contents of v

 

 

1. ostream iterator ์˜ delimiter (์ถœ๋ ฅ ๋ฐ˜๋ณต์ž์˜ ๊ตฌ๋ถ„์ž)

ostream_iterator<Type> out(ostream&, char* deLimit);

deLimit์ด๋ผ๋Š” ๊ตฌ๋ถ„์ž๋ฅผ ํ†ตํ•ด char๋‹จ์œ„๋กœ ์ชผ๊ฐœ์„œ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Œ

 

์˜ˆ์‹œ:

ostream iterator<int> screen2(cout, " ");
copy(v.begin(), v.end(), screen2);
	// will output the contents of v
	// seperated by a space

 

2. range-based FOR loop

vector<int> aVector = {1, 2, 3, 4, 5};
for (int i : aVector)
	cout << i << " ";

- less prone to errors : ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜๋Š” out-of-bonds ์ ‘๊ทผ์„ ๋ฐฉ์ง€ ํ•˜๊ธฐ๋•Œ๋ฌธ์— ์˜ค๋ฅ˜ ๋ฐœ์ƒ๋ฅ ์ด ์ ์Œ 

- Does not use a counter variable : ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ „ํ†ต์ ์ธ for loop์™€ ๋‹ฌ๋ฆฌ ์ปจํ…Œ์ด๋„ˆ์˜ ์š”์†Œ๋ฅผ ์ง์ ‘ ์‚ฌ์šฉ.  ๋ฐ˜๋ณต ๋ณ€์ˆ˜๋ฅผ ๋”ฐ๋กœ ์„ ์–ธํ•˜๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธํ•  ํ•„์š”๊ฐ€ ์—†์Œ 

- Does not use a subscript operator : ๋ฐฐ์—ด์ ‘๊ทผ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€์•Š์Œ ! ์ปจํ…Œ์ด๋„ˆ์˜ ์š”์†Œ๋ฅผ ์ง์ ‘ ์ฐธ์กฐํ•จ

 

vector<string> aVector = {"First", "Middle", "Last"};
for(const string& i : aVector)
	cout << i << " ";

-> ์ฐธ์กฐ์‚ฌ์šฉํ•˜๊ธฐ !

 

3. AUTO !!

vector<int> aVector = {1, 2, 3, 4};

auto iter = aVector.begin();
auto iterEnd = aVector.end();

for(iter; iter != iterEnd; ++iter)
	cout << *iter;

 

์žฅ์  : initialization expression ์—์„œ ํ˜•์„ ์œ ์ถ”ํ•˜๊ฒŒ ํ•˜์—ฌ ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์„ ๋†’์ž„. ex: (string) ์ผ์ผ€ํ•˜๋ฉด ๋„ˆ๋ฌด ๊ธธ๋‹ค..

๋‹จ์  : ๋ณ€์ˆ˜์˜ ํƒ€์ž…์ด ๋ช…ํ™•ํ•˜์ง€์•Š๊ฑฐ๋‚˜ ์ถ”๋ก ์ด ๋ณต์žกํ•  ๊ฒฝ์šฐ ์˜คํžˆ๋ ค ๊ฐ€๋…์„ฑ์„ ํ•ด์น  ์ˆ˜ ์žˆ์Œ ! 

 

 

 

๋ ! 

ostream๊ฒ๋‚˜ ์–ด๋ ต๋„ค.. ๋จผ์†Œ๋ฆฐ์ง€ ๋ชจ๋ฅด๊ฒ ๋‹ค ; /Mar 29 2024

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

๋ชŒ?

 

~ ์ˆœํ™˜ ๋ฐ˜๋ณต์ž ~

for ๋ฌธ๊ณผ while๋ฌธ์œผ๋กœ ์‹ธ์ดํด์„ ๋Œ๋ ค๋ณด์•„์š”.. 

 

vector<int> v = {1, 2, 5, 7, 8};
vector<int> const_iterator iter = v.cbegin(); 
vector<int> const_iterator iterEnd = v.cend();

for(iter; iter != iterEnd; ++iter) //NULLPTR๊ฐ€ ์•„๋‹๋•Œ๊นŒ์ง€ ์‹ธ์ดํด
{
	cout << *iter <<endl;
}

while(iter != iterEnd) 
{
	cout << *iter << endl;
    ++iter;
}

 

์ž˜ํ–ˆ๋‚˜์š”..? ์‚ฌ์‹ค for๋ฌธ์—์„œ !=์„ ์“ฐ๋Š”๊ฑด ์•„์ฃผ ์œ„ํ—˜ํ•˜๋‹ค๊ตฌ ํ•ฉ๋‹ˆ๋‹ค.. 

while๋ฌธ์œผ๋กœ ์จ๋ณด๋Š” ์Šต๊ด€์„ ๊ธฐ๋ฅด์ž ! ์•„์ž์•„์ž ! 

 


 

๊ฑฐ๊พธ๋กœ ์‹ธ์ดํด์„ ๋Œ๋ ค๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผ๋ ๊นŒ์š”??

iter ์„ v.cend() ์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ๋ฐ˜๋Œ€๋กœ ๋Œ๋ฆฌ๋ฉด ๋˜์ง€์•Š์„๊นŒ? ๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์ง€๋งŒ 

v.cend() function์€ null๊ฐ’์„ ๊ฐ€๋ฅดํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ํ• ์ˆ˜ ์—†์Œ !!!!

for(iter; iter != iterBegin; --iter) // DOES NOT WORK!

 

์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” Cycling in Reverse Order ์œผ๋กœ๋„ ํ•ด๋ณผ ์ˆ˜ ์žˆ๋”ฐ! 

vector<char>::reverse_iterator revIter = v.rbegin();

์ฐธ์‰ฝ์ ธ ใ…Žใ…Ž

 

๋งŒ์•ฝ์— const๋ฅผ ์“ฐ๊ณ  ์‹ถ๋‹ค๋ฉด 

vector<char>::const_reverse_iterator constRevIter = v.crbegin();
vector<char>::const_reverse_iterator constRevIterEnd = v.crend();
for(constRevIter; constRevIter != constRevIterEnd; ++constRevIter)
	cout << *constRevIter << endl;

์ด๋ ‡๊ฒŒ ๊ฐ„๋‹ค!  ์‚ฌ์‹ค์ƒ ๋’ค๋กœ(backwards)๋กœ ์›€์ง์ด๋Š” ๊ฑฐ์ง€๋งŒ, ++์„ ์จ์•ผํ•จ! ์™œ๋ƒ,., ์ด๊ฑด REVERSE๋‹ˆ๊นŒ.. 

 

 

~summary~

Predefined iterator Direction of ++  Actions Uses features
iterator forward read/write begin/end vector<char>::iterator iter = v.begin();
cosnt_iterator forward read cbegin/cend vector<char>::const_iterator constIter = v.cbegin();
reverse_iterator backward read/write rbegin/rend vector<char>::reverse_iterator revIter = v.rbegin();
const_reverse_iterator backward read crbegin/crend vector<char>::const_reverse_iterator constRevIter = v.crbegin();

 

๋ ใ…Žใ…Ž

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

 

 

1. begin() 

vector<int> v = { 10, 20, 30, 40, 50, 60 };
cout << *(v.begin( ) + 4); // will print 50
vector<int>::iterator iter = v.begin( ) + 2;

// iter will point to 30

++iter; // moves iter forward
cout << *iter; // will print 40

 

2. end()

end function์€ ๊ทธ๋ƒฅ FLAG!!

* last element ๋ฅผ ํฌ์ธํŠธ ํ•˜์ง€์•Š์Œ 

* --v.end() ๋Š” value๊ฐ€ unpredictableํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์“ธ์ˆ˜์—†์Œ 

 

3. Constant iterators ์ƒ์ˆ˜ํ˜• ๋ฐ˜๋ณต์ž 

- ์ปจํ…Œ์ด๋„ˆ์˜ ์š”์†Œ๋ฅผ ๋ฐ˜๋ณตํ•˜์—ฌ ์ฝ๊ธฐ๋งŒ ํ• ๋•Œ ์‚ฌ์šฉ

- ๋ฒกํ„ฐ์˜ ์š”์†Œ๋ฅผ ๋ฐ˜๋ณตํ•˜๋ฉด์„œ ํ•ด๋‹น ์š”์†Œ๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ์ถœ๋ ฅ 

-  ์ปจํ…Œ์ด๋„ˆ ์š”์†Œ๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋Š” ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉ 

vector<char>::const_iterator iter = v.cbegin();
*iter = 39; // illegal

 

4. Cycling Iterators ์ˆœํ™˜ ๋ฐ˜๋ณต์ž 

vector<int> v = {1,2,3,4};
vector<int>::const_iterator iter = v.cbegin();
vector<int>::const_iterator iterEnd = v.cend();
for (iter; iter != iterEnd; ++iter)

cout << *iter;
//*iter is current data item
vector<int> = {1,2,3,4,5};
vector<int>::const_iterator iter = v.cbegin();
vector<int>::const_iterator iterEnd = v.cend();
while (iter != iterEnd)
{

...
++iter;
//*iter is current data item

}
 
 

์ˆœํ™˜๋ฐ˜๋ณต์ž .. ๋‹ค์ŒํŽธ์—์„œ ๊ณ„์† .. ^ใ……^

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

 

 

~ Container๋ฅผ ์‚ดํŽด๋ณด๊ธฐ ์ „์— Iterator๋ฅผ ์‚ดํŽด๋ด…์‹œ๋‹ค ~

 

 

Container classes make an intensive use of iterators to .... 

1. ์ปจํ…Œ์ด๋„ˆ์— ๋“ค์–ด๊ฐ€๋Š” ๋ฐ์ดํ„ฐ๋“ค์˜ ์ˆœํ™˜์„ ๋„์›€

2. ๊ฐ๊ธฐ ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ๋“ค์—๊ฒŒ ๋™์ผํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณต (provide uniform interface)

3. ๋ฐ˜๋ณต์ž๋Š” ํฌ์ธํ„ฐ์˜ "์ผ๋ฐ˜ํ™” ๋œ ๊ฐœ๋…"์ด๋‹ค. -> ํฌ์ธํ„ฐ๋Š” ์•„๋‹˜! ์ถ”์ƒํ™”๋œ ๊ฐœ๋…! (A generalization of a pointer) 

4. An iterator variable points to one data entry in the container  

5. Each container has its "own" iterator type -> ๋ฐ์ดํ„ฐํƒ€์ž… ๋“ค์ด ๊ทธ๋“ค๋งŒ์˜ ๋ฐ˜๋ณต์ž ํƒ€์ž…์„ ๊ฐ–๊ณ ์žˆ๋Š”๊ฑฐ๋ž‘ ์œ ์‚ฌํ•จ! 

์˜ˆ์‹œ ; 

// Container type's own iterator type
std::vector<int> myVector;
std::vector<int>::iterator iter; // ๋ฒกํ„ฐ์— ๋Œ€ํ•œ iterator ํƒ€์ž…
std::list<double> myList;
std::list<double>::iterator iter; // ๋ฆฌ์ŠคํŠธ์— ๋Œ€ํ•œ iterator ํƒ€์ž…
std::map<std::string, int> myMap;
std::map<std::string, int>::iterator iter; // ๋งต์— ๋Œ€ํ•œ iterator ํƒ€์ž…
std::set<float> mySet;
std::set<float>::iterator iter; // ์„ธํŠธ์— ๋Œ€ํ•œ iterator ํƒ€์ž…

// Data type's their own pointer type 
int* dynamicArray = new int[10];
int* iterator = dynamicArray; // ๋™์  ๋ฐฐ์—ด์— ๋Œ€ํ•œ ๋ฐ˜๋ณต์ž ํƒ€์ž…
std::string str = "Hello";
std::string::iterator iter = str.begin(); // ๋ฌธ์ž์—ด์— ๋Œ€ํ•œ ๋ฐ˜๋ณต์ž ํƒ€์ž…
int arr[5] = {1, 2, 3, 4, 5};
int* iter = arr; // ๋ฐฐ์—ด์— ๋Œ€ํ•œ ๋ฐ˜๋ณต์ž ํƒ€์ž…
int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int* iter = *matrix; // ๋งคํŠธ๋ฆญ์Šค์— ๋Œ€ํ•œ ๋ฐ˜๋ณต์ž ํƒ€์ž…

 

 

<๋ฐ˜๋ณต์ž์— ๋Œ€ํ•œ ๋ฉค๋ฒ„ํ•จ์ˆ˜๋“ค - member functions for iterators>

ct.begin() : Returns an iterator for the container ct that points to the first data item in ct(container) 

ct.end() : It is a flag and does NOT return the last element - IT IS LIKE NULL !!!!!!

 

 

<Iterator Operators>

++iter 
--iter
์ „์œ„ ์—ฐ์‚ฐ์ž Moves the iterator one position forward/backward 
iter++
iter-- 
ํ›„์œ„ ์—ฐ์‚ฐ์ž Moves the iterator one positionforward/backward
iter += i 
iter -= i
i๋งŒํผ  ํฌ์ง€์…˜์— ๋Œ€ํ•ด ์ฆ๊ฐ€ or ๊ฐ์†Œ 
*iter ๋ฐ˜๋ณต์ž ์ฐธ์กฐ ? Returns the value of the item the iterator is pointing to.
iter1 = iter2 Assigns one iterator to another
The POSITION is assigned (๋ฐ˜๋ณต์žํฌ์ธํ„ฐ - ์ถ”์ƒ์  ๊ฐœ๋…์ž„!!!! ๊ฐ€ ๊ฐ€๋ฅดํ‚ค๋Š” value๊ฐ€ ์•„๋‹Œ ์œ„์น˜๊ฐ€ assigned๋จ)
iter1 == iter2 / iter1 != iter2  value ๊ฐ€ ์•„๋‹ˆ๋ผ position์œผ๋กœ ๋น„๊ต ! (Will return TRUE/FALSE if the iterators are pointing the same item) 
iter[i] / *(iter + i) Returns the VALUE of the item that is positioned i indices to the right of where the iterator is positioned. (Does NOT move the iterator) 

๋‘˜์€ ํ‘œ๋ฉด์ ์œผ๋กœ๋Š” ๊ฐ™์€ ์—ญํ• ์„ ํ•˜์ง€๋งŒ, ๋‚ด๋ถ€์ ์œผ๋กœ๋Š” ๋‹ค๋ฅด๊ฒŒ ๋Œ์•„๊ฐ! 
1. iter[i] : iter์—์„œ i ๋งŒํผ ๋–จ์–ด์ ธ์žˆ๋Š” ๊ณณ์„ ์ฐพ๊ณ , ๊ทธ๋‹ค์Œ์— ๊ทธ ์œ„์น˜์— ์žˆ๋Š” ๊ฐ’์„ ์คŒ 
2. *(iter + i) : iter์„ i ๋งŒํผ ์ฆ๊ฐ€์‹œํ‚ค๊ณ , ๊ทธ๋‹ค์Œ์— ๊ทธ ์œ„์น˜์— ์žˆ๋Š” ๊ฐ’์„ ์คŒ 

 

 

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

< STL > 

- Standard Template Library (STL) : library of classes and associated functions 

- ํ•œ๊ตญ์–ด๋กœ๋Š” ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ผ๊ณ  ํ•œ๋‹ค. 

- template-based components ๋ฅผ ํ†ตํ•ด software reuse์„ ํ•จ.  -> ์ด๋Š” ํƒ€์ž…์˜ ์ผ๋ฐ˜ํ™”๋กœ ๋งํ•  ์ˆ˜์žˆ์Œ 

: which is "GENERIC PROGRAMMING ! " ( vs functional programming - ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ) 

 

<STL ์˜ ๊ตฌ์„ฑ์š”์†Œ> 

1. Containers : ์ปจํ…Œ์ด๋„ˆ 

- Data structures capable of storing objects of almost any data type (there are some restrictions) 

- ํ”ํžˆ stl ์ž๋ฃŒ๊ตฌ์กฐ๋ผ๋Š” ๊ฒƒ์ด stl container์œผ๋กœ ํ†ต์šฉ๋œ๋‹ค. (์ปฌ๋ ‰์…˜์ด๋ผ ์นญํ•˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์Œ) 

 

2. Iterators ( -> objects) : ๋ฐ˜๋ณต์ž 

- Used to step through the elements of a container

- ํฌ์ธํ„ฐ ๊ฐ™์€๊ฑฐ 

 

3. Algorithms ( = non-member functions) : ์•Œ๊ณ ๋ฆฌ์ฆ˜ 

- Functions that perform common data maniputation such as sorting, searching, and comparing elements (or entire contatiners) 

- sorting, searching, comparing ๊ฐ™์€ ์ผ๋ฐ˜์ ์ธ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ๊ทœ๊ฒฉํ™” - ํ˜•์‹ํ™” ํ•ด๋†“์€ ๋ฐฉ๋ฒ•?? 

 

<STL ์˜ ์žฅ์ > 

- ๊ฐœ๊ฐ€ํ‹ฐ ๋น ๋ฅด๋‹ค 

- ์งœ์—ฌ์ ธ ์žˆ๋Š” ํ…œํ”Œ๋ฆฟ์„ ์ ์žฌ์ ์†Œ์— ๋„ฃ์œผ๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ํšจ์œจ์„ฑ์ด ๋ฌด์Ÿˆ๊ฒŒ ์˜ฌ๋ผ๊ฐ„๋‹ค 

 

.. ๋‹จ์ ์€ ์•„์ง ๋ชจ๋ฅด๊ฒŸ์Œ ใ…‹. ( ๊ทธ์น˜๋งŒ ์•„๋งˆ Generic programming์˜ ๋‹จ์ ์ด ๊ทธ๋Œ€๋กœ ๊ฐ€์ง€์•Š์„๊นŒ ํ•˜๋Š” ์ƒ๊ฐ์ด ๋“ ๋‹ค) 

 

 

 

๋‹ค์Œ์€ STL์˜ Iterator์— ๋Œ€ํ•ด์„œ ์•„๋ผ๋ณด์ž 

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

ใ„ใคใ‚ตใƒƒใƒผใ‚ซใƒผใ‚„ใฃใฆใ‚‹ใฎ๏ผŸใ€€๏ผš ์ถ•๊ตฌ ์–ธ์ œํ•ด ?? .. ์‚ฌ์‹ค ๋„˜ ์‰ฌ์šด ์ผ๋ณธ์–ด๋ผ ํ•œ๋ฒˆ์— ์•Œ์•„๋“ค์—ˆ๋”ฐ 

 

๊ทธ์น˜๋งŒ ์ƒˆ๋กœ์šด ์‚ฌ์‹ค 

1. ์ด์ธ  ์‚ฌ์นด์–๋–ผ๋ฃจ๋…ธ? ๋„ ํ• ์ˆ˜ ์žˆ์ง€๋งŒ 

2. ์‚ฌ์นด ์ด์ธ  ์–๋–ผ๋ฃจ๋…ธ?? ๋„ ํ• ์Šˆ์žˆ๋‹น ใ…Žใ……ใ…Ž 

 

ใ„ใค๋Š”ใ€€ใ„ใคใ‚‚ใชใ‚“ใฉใงใ‚‚(์–ธ์ œ๋‚˜ ๋ช‡๋ฒˆ์ด๋ผ๋„) ์—์„œ์ฒ˜๋Ÿผ ์–ธ์ œ? .. ์ž„ 

 

ใ‚„ใฃใฆใ‚‹ ๋Š” ์•ผ๋ฃจ (~ํ•˜๋‹ค?) ์˜ ์˜๋ฌธ + ์ง„ํ–‰ํ˜• ์ธ๋ฐ 

์—ฌ๊ธฐ์„œ ์ถ•๊ตฌ๋ฅผ ํ•˜๋‹ค๋Š” ใ‚ตใƒƒใƒผใ‚ซใƒผใ‚’ใ‚„ใ‚‹ใ€‚๋ผ๊ตฌ ์ƒ๊ฐํ• ์ˆ˜ ์žˆ์ง€๋งŒ ์‚ฌ์นด๋Š” ์Šค๋ฃจ๋‹ค .. 

์ถ•๊ตฌ์–ด๋””์„œ ํ• ๊บผ์•ผ๋Š” : ์‚ฌ์นด ๋„์ฝ”๋ฐ ์Šค๋ฃจ๋…ธ? ์‚ฌ์นด ๋„์ฝ”๋‹ˆ ์Šค๋ฃจ๋…ธ?? ์ •๋„๊ฐ€ ๋ ๊ฑฐ๊ฐ™๋‹ค(๊ณ  ์ƒ๊ฐํ•œ๋‹น.....) 

๋ฐ ๋‹ˆ ๋Š” ์•„์ง๋„ ๊ตฌ๋ถ„ ๋ชจ๋‹จ๋‹ค . 

๊ทผ๋ฐ ๋˜ ์•ผ๋ฃจ๊ฐ€ ๋ญ๋ƒ๊ตฌ ํ•˜๋ฉด ์ข€ ๊ณค๋ž€ํ•ด์ง€๋Š”๋ฐ ์™œ๋ƒ๋ฉด ์ผ๋‹จ ๋‚ด๊ฐ€ ์ƒ๊ฐํ–ˆ์„๋•Œ๋Š” ์ „ํ˜€ ์™€๋‹ฟ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค ..

๋‚˜์˜ ์งง์€ ์ผ๋ณธ์–ดํšŒํ™” ์•Œ์•„๋“ฃ๊ธฐ ๋Šฅ๋ ฅ์œผ๋กœ๋Š” ... 

์•ผ๋ฃจ -> ใ‚„ใฃใŸใœ๏ผ๏ผ๏ผˆํ•ด๋ƒˆ๋‹ค!!)   ใ‚„ใฃใฆใฟใ‚ˆใฃใ‹ใช๏ผˆํ•ด๋ณผ๊นŒ๋‚˜ ~~ ) ์ด๋Ÿฐ๊ฑฐ๊ณ  

์Šค๋ฃจ -> ๅ‹‰ๅผทใ™ใ‚‹ใจใ‹ใ‚ตใƒƒใƒผใ‚ซใƒผใ™ใ‚‹ใ€ใ€ใ€๋Œ€์ถฉ ์š”์•ฝ : ์•ผ๋ฃจ๊ฐ€ ์ข€๋” casualํ•˜๋‹ค๊ตฌ ์ƒ๊ฐํ•ด

 

์• ๋“คํ•œํ…Œ ๋ฌผ์–ด๋ด์•ผ๊ฒ ๋‹ค .........

 


๋‘๋ฒˆ์งธ .. 

์นญ๊ตฌ๋“ค์ด๋ž‘ ์–˜๊ธฐํ•˜๋‹ค๊ฐ€ ๋‚ด๊ฐ€ ์ผ€๋ฏธ์˜ค๋กœ ์ผ๋ณธ์–ด๋กœ ๊ณต๋ถ€ ํ•œ๋‹ค ํ•˜๋‹ˆ๊นŒ ๋‚œ๋ฆฌ๊ฐ€ ๋‚˜๋ฒ„๋ ค์„œ .. 

๋˜ ๋‚ด๊ฐ€ ํŒฌ์„œ๋น„์Šค๋กœ ใ‚ขใ‚ฒใ‚ขใ‚ฒใƒผ๋ฅผ ํ•ด์ฃ ๋”ฐ ใ…Žใ…Ž

์—ฌ๊ธฐ์„œ ์•„๊ฒŒ์•„๊ฒŒ๋Š” ๊ทธ๋ƒฅ ๊ฐธ๋ฃจ ๊ฐํƒ„์‚ฌ (?) ๊ทธ๋Ÿฐ๊ฑฐ๋ผ์„œ .. ์ด๊ฑฐ๋Š” ๋ชจ๋ฅด๊ฒ ๊ตฌ 

์•„๊ฒŒ ๋œป๋„ ๋ฌผ์–ด๋ดค๋Š”๋ฐ ๊ทธ๊ฑด ๊นŒ๋จน์—ˆ๊ตฌ 

ใƒ†ใƒณใ‚ทใƒงใƒณใ‚ใŒใฃใฆใพใ™ใ€‚๏ผšI'm highใ€€๏ผˆใƒ†ใƒณใ‚ทใƒงใƒณไธŠใŒใฃใฆใพใ™ใ€‚๏ผ‰

ใƒ†ใƒณใ‚ทใƒงใƒณใŸใ‹ใ„ใ€‚ใ€€๏ผšI'm high ๏ผˆใƒ†ใƒณใ‚ทใƒงใƒณ้ซ˜ใ„ใ€‚๏ผ‰

๋‘˜๋‹ค ํ•˜์ดํ•˜๋‹ค ์ •๋„์˜ ๋Š๋‚Œ์ด๋‹น . . 

 

 

๋ .... 

 

 

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/ๆ—ฅๆœฌ่ชž' Related Articles +
 
 
 

## Assuming that you are not implementing a portion of the standard library, which of these are legal identifiers. (This means that they follow the syntax rules for C++)

 

- switch 

- _int 

- string 


 

what is  L-Value, R-Value or Non-Modifiable L-Value. ??? 

 

In C++ and many other programming languages, the terms "L-value" and "R-value" are used to classify expressions based on whether they can appear on the left side of an assignment (`=`) operator or not. Additionally, there's a concept called "non-modifiable L-value," which refers to an L-value that cannot be modified. Here's an explanation of these terms:

1. **L-Value (Left Value)**:
   - **Definition**: An L-value is an expression that refers to a memory location, and it can appear on the left side of an assignment operator (`=`). In other words, it represents an object or variable that can be modified.
   - **Example**: Variables, array elements, and non-const references are typically L-values. For instance, `int x = 5;` - here, `x` is an L-value.

2. **R-Value (Right Value)**:
   - **Definition**: An R-value is an expression that represents a value and cannot appear on the left side of an assignment operator. R-values are typically temporary and may not have a memory location.
   - **Example**: Literal values (`5`, `"hello"`), the result of an expression (`x + y`), and function return values are often R-values.

3. **Non-Modifiable L-Value**:
   - **Definition**: A non-modifiable L-value is an expression that refers to a memory location like an L-value but cannot be modified. It represents an object that is marked as const.
   - **Example**: A const variable (`const int y = 10;`) is a non-modifiable L-value because you cannot modify its value.

Here are some examples to illustrate these concepts:

```cpp
int x = 5;         // 'x' is an L-value.
int y = x + 3;     // 'x + 3' is an R-value (temporary result).
const int z = 7;   // 'z' is a non-modifiable L-value (const variable).

x = 10;            // 'x' is an L-value, and it can be modified.
// 'y = 15;' would be a compilation error because 'y' is an R-value.
// 'z = 8;' would be a compilation error because 'z' is a non-modifiable L-value.
```



In summary, L-values are expressions that can appear on the left side of an assignment, R-values are expressions that represent values and cannot be on the left side of an assignment, and non-modifiable L-values are L-values that are marked as const and cannot be modified.

 


 

1. **๋ฌธ์ž์—ด ๊ธธ์ด() ๋ฉค๋ฒ„ ํ•จ์ˆ˜์—์„œ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค:** ์•„๋‹ˆ์š”, ๋ฌธ์ž์—ด ํด๋ž˜์Šค์˜ `length()` ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋Š” `string::size_type`์„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ `size_t`๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

2. **ํ•ด๋‹น ํ˜•์‹์˜ ๋ณ€์ˆ˜๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:** ์˜ˆ, `string::size_type` ํ˜•์‹์˜ ๋ณ€์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ๋ฌธ์ž์—ด๊ณผ ๊ด€๋ จ๋œ ํฌ๊ธฐ ๋ฐ ์ธ๋ฑ์Šค๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3. **`size_t`์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค:** ์ผ๋ฐ˜์ ์œผ๋กœ `string::size_type`๊ณผ `size_t`๋Š” ๋™์ผํ•˜๊ฑฐ๋‚˜ ๋งค์šฐ ์œ ์‚ฌํ•œ ํ˜•์‹์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‘ ํ˜•์‹์ด ํ•ญ์ƒ ๋™์ผํ•˜๋‹ค๊ณ  ๋ณด์žฅ๋˜์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค.

4. **unsigned ์ •์ˆ˜ ํ˜•์‹์ด๋ฉฐ ์–ด๋–ค ํฌ๊ธฐ์˜ ํ˜•์‹์ž…๋‹ˆ๋‹ค:** ๋งž์Šต๋‹ˆ๋‹ค, `string::size_type`์€ ๋ณดํ†ต ์–ด๋–ค ํฌ๊ธฐ์˜ unsigned ์ •์ˆ˜ ํ˜•์‹์ž…๋‹ˆ๋‹ค.

5. **๋ฌธ์ž์—ด size() ๋ฉค๋ฒ„ ํ•จ์ˆ˜์—์„œ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค:** ๋งž์Šต๋‹ˆ๋‹ค, ๋ฌธ์ž์—ด ํด๋ž˜์Šค์˜ `size()` ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋Š” `string::size_type`์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

 
 

if ๋’ค์— ; ๋ถ™์–ด์„œ ์ •๋‹ต์€ 3๋ฒˆ ..

 

'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +

์ด ์•„์ด์˜ ํŠน์ง• .. 

1. native code 

2. machine language

3. machine dependent 

 

This code is written in machine (and assembly) language for a specific processor; thus it is non-portable or machine dependent. This is the native code for the 6502 processor. Machine language is both difficult to write and to understand. (That's why Woz added all of the comments on the right).

 

 

 

step 1 - text editor : vim ๊ฐ™์€๊ฑฐ ! ์ฒ˜์Œ์— ํ…์ŠคํŠธ ์—๋””ํ„ฐ๋กœ ์ฝ”๋“œ ์ž‘์„ฑํ•จ 

step 2 - preprocessor : Performs text substitution on your source code / Converts processed source code to object code.

step 3 - compiler : converts processed source code to object code 

step 4 - linker : combines object files with library code to produce the executable image, 

step 5 - loader : reads the program on disk, loads any required shared libraries and starts the program running.

step 6 - CPU : responsible for executing your code 

 

๊ทธ๋‹ˆ๊นŒ 1. ๋น”์œผ๋กœ ํ…์ŠคํŠธ ์จ์„œ ์ฝ”๋“œ ์“ฐ๋ฉด 2. ํ”„๋ฆฌํ”„๋กœ์„ธ์„œ๊ฐ€ ์ ์€ ํ…์ŠคํŠธ๋ฅผ ์ฝ”๋“œ๋กœ substituteํ•˜๊ณ   3. ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ sourcecode ๋ฅผ object code ๋กœ convert ํ•ด 4. ์ปด์ฐจ์ผ์ด ๋˜๋ฉด ๋ง์ปค๊ฐ€ ๋ญ”๊ฐ€ ๊ฒฐ๊ณผ๋ฅผ ๋‚ด๊ธฐ์œ„ํ•ด์„œ ๋งค์น˜๋ฅผ ๋งํฌ๋ฅผ ํ•จ 5. ๋กœ๋”ฉ์„ ํ•จ 6. ๊ฒฐ๊ณผ๋ฅผ ๋ƒ„ ???

 

 

/**
 *  @author Jimin
 *  @date Thu Aug 31
 *  @file h01.cpp
 */ -> (1) documentation comment
 
#include <iostream>
#include <string>
#include <iomanip> // -> (2) standard library

using namespace std; // -> (3) namespace directive

double convert(double temp); // -> (4) function prototype 

int main()
{
cout << "Enter a temperature in ํ™”์”จ"; // -> (6) prompt
double fahr; // -> (7) variable statement 
cin >> fahr;
double celsius = convert(fahr); //-> (9) function call 
cout << "Converted: " << fanhr << "F -" << celsius << "C" << endl; // -> (10) output statement 
return 0; // -> (11) optional return 

double convert(double temp) // -> (14) parameter
{
return (temp -32 ) * 5.0 /9.0; // -> (13) expression
} 
// -> (12) function definition
 
1. Provides an initial value for a variable when it is created.
 - initialization
2. Associates a name with a type.
- declaration
3. Allocates memory for a new variable.
- definition
4. Types like the string type.
- library types
5. Places a value into an existing variable.
- assignment 
 
6. A set of bits interpreted according to a type.
- value        
'เซฎโ‚หถแต” แต• แต”หถโ‚Žแƒโ™ก/coding' Related Articles +