-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopics.cpp
More file actions
77 lines (66 loc) · 1.79 KB
/
Topics.cpp
File metadata and controls
77 lines (66 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Learn_CPP.h"
// Function to initialize topics
std::unordered_map<std::string, Topic> initializeTopics() {
std::unordered_map<std::string, Topic> topics;
// Array Topic
topics["Array"] = {
"An array is a collection of elements of the same type stored in contiguous memory locations. Arrays allow random access using indices.",
R"(Syntax:
dataType arrayName[arraySize];
Example:
int arr[5] = {1, 2, 3, 4, 5};)",
R"(Example Code:
#include <iostream>
using namespace std;
int main() {
int arr[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
cout << "Element " << i << ": " << arr[i] << endl;
}
return 0;
})"
};
// Function Topic
topics["Functions"] = {
"Functions are blocks of code designed to perform a specific task. They help in modular programming, making code reusable and easier to understand.",
R"(Syntax:
returnType functionName(parameters) {
// Function body
}
Example:
int add(int a, int b) {
return a + b;
})",
R"(Example Code:
#include <iostream>
using namespace std;
int add(int a, int b) {
return a + b;
}
int main() {
int x = 5, y = 10;
cout << "Sum: " << add(x, y) << endl;
return 0;
})"
};
// Pointer Topic
topics["Pointers"] = {
"Pointers are variables that store the memory address of another variable. They are used for dynamic memory allocation, arrays, and function arguments.",
R"(Syntax:
dataType* pointerName;
Example:
int* ptr;)",
R"(Example Code:
#include <iostream>
using namespace std;
int main() {
int var = 10;
int* ptr = &var;
cout << "Value of var: " << var << endl;
cout << "Address of var: " << ptr << endl;
cout << "Value at the address: " << *ptr << endl;
return 0;
})"
};
return topics;
}