Skip to content

Commit e921f36

Browse files
committed
Added section12 material.
1 parent 4843d24 commit e921f36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4209
-0
lines changed
6 KB
Binary file not shown.

Section12_Pointers_and_Reference/README.md

+479
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Session Name="C:\Users\frank\Desktop\CPPExamples\Section12\Section12.workspace">
3+
<int Value="0" Name="m_selectedTab"/>
4+
<wxString Value="C:\Users\frank\Desktop\CPPExamples\Section12\Section12.workspace" Name="m_workspaceName"/>
5+
<TabInfoArray Name="TabInfoArray"/>
6+
<SerializedObject Name="m_breakpoints">
7+
<long Value="1" Name="Count"/>
8+
<SerializedObject Name="Breakpoint0">
9+
<wxString Value="C:\Users\frank\Desktop\CPPExamples\Section12\Debugger\main.cpp" Name="file"/>
10+
<int Value="16" Name="lineno"/>
11+
<wxString Value="" Name="function_name"/>
12+
<wxString Value="" Name="memory_address"/>
13+
<int Value="1" Name="bp_type"/>
14+
<int Value="0" Name="watchpoint_type"/>
15+
<wxString Value="" Name="watchpt_data"/>
16+
<CData Name="commandlist"/>
17+
<bool Value="0" Name="regex"/>
18+
<bool Value="0" Name="is_temp"/>
19+
<bool Value="1" Name="is_enabled"/>
20+
<int Value="0" Name="ignore_number"/>
21+
<wxString Value="" Name="conditions"/>
22+
<int Value="0" Name="origin"/>
23+
</SerializedObject>
24+
</SerializedObject>
25+
</Session>
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
C:\Users\frank\Desktop\CPPExamples\Section12\ChallengeSolution\main.cpp
2+
C:\Users\frank\Desktop\CPPExamples\Section12\Debugger\main.cpp
3+
C:\Users\frank\Desktop\CPPExamples\Section12\Challenge\main.cpp
4+
C:\Users\frank\Desktop\CPPExamples\Section12\SimplePointers\main.cpp
5+
C:\Users\frank\Desktop\CPPExamples\Section12\Dereference\main.cpp
6+
C:\Users\frank\Desktop\CPPExamples\Section12\DynamicMemory\main.cpp
7+
C:\Users\frank\Desktop\CPPExamples\Section12\References\main.cpp
8+
C:\Users\frank\Desktop\CPPExamples\Section12\AraysAndPointers\main.cpp
9+
C:\Users\frank\Desktop\CPPExamples\Section12\PassingPointers2\main.cpp
10+
C:\Users\frank\Desktop\CPPExamples\Section12\PointerArithmetic\main.cpp
11+
C:\Users\frank\Desktop\CPPExamples\Section12\PassingPointers\main.cpp
12+
C:\Users\frank\Desktop\CPPExamples\Section12\PassingPointers3\main.cpp
13+
C:\Users\frank\Desktop\CPPExamples\Section12\ReturnPointer\main.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CodeLite_Project Name="ArraysAndPointers" Version="10.0.0" InternalType="User templates">
3+
<Plugins>
4+
<Plugin Name="qmake">
5+
<![CDATA[00010001N0005Debug000000000000]]>
6+
</Plugin>
7+
</Plugins>
8+
<Description/>
9+
<Dependencies/>
10+
<Settings Type="Executable">
11+
<GlobalSettings>
12+
<Compiler Options="-std=c++14;-Wall" C_Options="" Assembler="">
13+
<IncludePath Value="."/>
14+
</Compiler>
15+
<Linker Options="">
16+
<LibraryPath Value="."/>
17+
</Linker>
18+
<ResourceCompiler Options=""/>
19+
</GlobalSettings>
20+
<Configuration Name="Debug" CompilerType="MinGW ( MinGW )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
21+
<Compiler Options="-g;-O0;-std=c++14;-Wall" C_Options="-g;-O0;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
22+
<IncludePath Value="."/>
23+
</Compiler>
24+
<Linker Options="" Required="yes"/>
25+
<ResourceCompiler Options="" Required="no"/>
26+
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
27+
<BuildSystem Name="Default"/>
28+
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
29+
<![CDATA[]]>
30+
</Environment>
31+
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="yes">
32+
<DebuggerSearchPaths/>
33+
<PostConnectCommands/>
34+
<StartupCommands/>
35+
</Debugger>
36+
<PreBuild/>
37+
<PostBuild/>
38+
<CustomBuild Enabled="no">
39+
<RebuildCommand/>
40+
<CleanCommand/>
41+
<BuildCommand/>
42+
<PreprocessFileCommand/>
43+
<SingleFileCommand/>
44+
<MakefileGenerationCommand/>
45+
<ThirdPartyToolName>None</ThirdPartyToolName>
46+
<WorkingDirectory/>
47+
</CustomBuild>
48+
<AdditionalRules>
49+
<CustomPostBuild/>
50+
<CustomPreBuild/>
51+
</AdditionalRules>
52+
<Completion EnableCpp11="no" EnableCpp14="yes">
53+
<ClangCmpFlagsC/>
54+
<ClangCmpFlags/>
55+
<ClangPP/>
56+
<SearchPaths/>
57+
</Completion>
58+
</Configuration>
59+
<Configuration Name="Release" CompilerType="MinGW ( MinGW )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
60+
<Compiler Options="-O2;-Wall" C_Options="-O2;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
61+
<IncludePath Value="."/>
62+
<Preprocessor Value="NDEBUG"/>
63+
</Compiler>
64+
<Linker Options="" Required="yes"/>
65+
<ResourceCompiler Options="" Required="no"/>
66+
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
67+
<BuildSystem Name="Default"/>
68+
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
69+
<![CDATA[]]>
70+
</Environment>
71+
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="yes">
72+
<DebuggerSearchPaths/>
73+
<PostConnectCommands/>
74+
<StartupCommands/>
75+
</Debugger>
76+
<PreBuild/>
77+
<PostBuild/>
78+
<CustomBuild Enabled="no">
79+
<RebuildCommand/>
80+
<CleanCommand/>
81+
<BuildCommand/>
82+
<PreprocessFileCommand/>
83+
<SingleFileCommand/>
84+
<MakefileGenerationCommand/>
85+
<ThirdPartyToolName>None</ThirdPartyToolName>
86+
<WorkingDirectory/>
87+
</CustomBuild>
88+
<AdditionalRules>
89+
<CustomPostBuild/>
90+
<CustomPreBuild/>
91+
</AdditionalRules>
92+
<Completion EnableCpp11="no" EnableCpp14="no">
93+
<ClangCmpFlagsC/>
94+
<ClangCmpFlags/>
95+
<ClangPP/>
96+
<SearchPaths/>
97+
</Completion>
98+
</Configuration>
99+
</Settings>
100+
<VirtualDirectory Name="src">
101+
<File Name="main.cpp"/>
102+
</VirtualDirectory>
103+
<Dependencies Name="Debug"/>
104+
<Dependencies Name="Release"/>
105+
</CodeLite_Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
##
2+
## Auto Generated makefile by CodeLite IDE
3+
## any manual changes will be erased
4+
##
5+
## Debug
6+
ProjectName :=ArraysAndPointers
7+
ConfigurationName :=Debug
8+
WorkspacePath :=C:/Users/frank/Desktop/CPPExamples/Section12
9+
ProjectPath :=C:/Users/frank/Desktop/CPPExamples/Section12/AraysAndPointers
10+
IntermediateDirectory :=./Debug
11+
OutDir := $(IntermediateDirectory)
12+
CurrentFileName :=
13+
CurrentFilePath :=
14+
CurrentFileFullPath :=
15+
User :=frank
16+
Date :=31/01/2018
17+
CodeLitePath :="C:/Program Files/CodeLite"
18+
LinkerName :=C:/MinGW/bin/g++.exe
19+
SharedObjectLinkerName :=C:/MinGW/bin/g++.exe -shared -fPIC
20+
ObjectSuffix :=.o
21+
DependSuffix :=.o.d
22+
PreprocessSuffix :=.i
23+
DebugSwitch :=-g
24+
IncludeSwitch :=-I
25+
LibrarySwitch :=-l
26+
OutputSwitch :=-o
27+
LibraryPathSwitch :=-L
28+
PreprocessorSwitch :=-D
29+
SourceSwitch :=-c
30+
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
31+
Preprocessors :=
32+
ObjectSwitch :=-o
33+
ArchiveOutputSwitch :=
34+
PreprocessOnlySwitch :=-E
35+
ObjectsFileList :="ArraysAndPointers.txt"
36+
PCHCompileFlags :=
37+
MakeDirCommand :=makedir
38+
RcCmpOptions :=
39+
RcCompilerName :=C:/MinGW/bin/windres.exe
40+
LinkOptions :=
41+
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
42+
IncludePCH :=
43+
RcIncludePath :=
44+
Libs :=
45+
ArLibs :=
46+
LibPath := $(LibraryPathSwitch).
47+
48+
##
49+
## Common variables
50+
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
51+
##
52+
AR := C:/MinGW/bin/ar.exe rcu
53+
CXX := C:/MinGW/bin/g++.exe
54+
CC := C:/MinGW/bin/gcc.exe
55+
CXXFLAGS := -std=c++14 -Wall -g -O0 -std=c++14 -Wall $(Preprocessors)
56+
CFLAGS := -g -O0 -Wall $(Preprocessors)
57+
ASFLAGS :=
58+
AS := C:/MinGW/bin/as.exe
59+
60+
61+
##
62+
## User defined environment variables
63+
##
64+
CodeLiteDir:=C:\Program Files\CodeLite
65+
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix)
66+
67+
68+
69+
Objects=$(Objects0)
70+
71+
##
72+
## Main Build Targets
73+
##
74+
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
75+
all: $(OutputFile)
76+
77+
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
78+
@$(MakeDirCommand) $(@D)
79+
@echo "" > $(IntermediateDirectory)/.d
80+
@echo $(Objects0) > $(ObjectsFileList)
81+
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
82+
83+
MakeIntermediateDirs:
84+
@$(MakeDirCommand) "./Debug"
85+
86+
87+
$(IntermediateDirectory)/.d:
88+
@$(MakeDirCommand) "./Debug"
89+
90+
PreBuild:
91+
92+
93+
##
94+
## Objects
95+
##
96+
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix)
97+
$(CXX) $(IncludePCH) $(SourceSwitch) "C:/Users/frank/Desktop/CPPExamples/Section12/AraysAndPointers/main.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath)
98+
$(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp
99+
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM main.cpp
100+
101+
$(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
102+
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) main.cpp
103+
104+
105+
-include $(IntermediateDirectory)/*$(DependSuffix)
106+
##
107+
## Clean
108+
##
109+
clean:
110+
$(RM) -r ./Debug/
111+
112+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./Debug/main.cpp.o
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main() {
6+
7+
int scores[] {100, 95, 89};
8+
9+
cout << "Value of scores: " << scores << endl;
10+
11+
int *score_ptr {scores};
12+
cout << "Value of score_ptr: " << score_ptr << endl;
13+
14+
cout << "\nArray subscript notation -------------------------" << endl;
15+
cout << scores[0] << endl; // Output: 100
16+
cout << scores[1] << endl; // Output: 95
17+
cout << scores[2] << endl; // Output: 89
18+
19+
cout << "\nPointer subscript notation -------------------------" << endl;
20+
cout << score_ptr[0] << endl; // Output: 100
21+
cout << score_ptr[1] << endl; // Output: 95
22+
cout << score_ptr[2] << endl; // Output: 89
23+
24+
cout << "\nPointer offset notation-------------------------" << endl;
25+
cout << *score_ptr << endl; // *address // Output: 100
26+
cout << *(score_ptr + 1) << endl; // *(address + 4) // Output: 95
27+
cout << *(score_ptr +2) << endl; // *(address + 8) // Output: 89
28+
29+
cout << "\nArray offset notation-------------------------" << endl;
30+
cout << *scores << endl; // Output: 100
31+
cout << *(scores + 1) << endl; // Output: 95
32+
cout << *(scores +2) << endl; // Output: 89
33+
34+
cout << endl;
35+
return 0;
36+
}
37+

0 commit comments

Comments
 (0)