SlideShare a Scribd company logo
Placement Preparation 
Arrays & Pointers 
Shobhit Chaurasia 
B.Tech, CSE
Target Audience 
People who have no prior coding experience, didn’t take 
CS101 seriously but want to learn some basics of coding 
quickly. 
If you know how write a program to sum up numbers in an 
array, and you DO NOT faint on seeing int ***ptr, then 
please don’t your waste time here; this tutorial is not for 
you.
Data types 
● int : -1000, -5, 0, 10, 2014 
● char : a, @, + 
● float : -10.35, 2.578 
● bool : True/False
More Data types 
● Array - {1,2,3,4} 
● String - “Ghissu” 
● Pointers
Arrays 
● Array is a collection of objects.
Arrays - 1D 
● int test[10]; // space for 10 ints 
● 0-based indexing 
● Index from 0 to (size - 1)
Array - initialization 
1D 
2D
Demo #1 
Store first 10 +ve integers in an array and 
print them.
Demo #2 
Sum up all the numbers in an array.
Demo #3 
Find the max. number in an array.
Demo #4 
Reverse the contents of an array. 
int arr[10]={1,2,3,4,5,6,7,8,9,10};
Arrays - 2D (Matrix) 
● int test_score[x][y] 
Row Index 
Column Index 
int test_score[10][4]
Demo #5 
Output contents of a 2D int array.
Demo #6 
char mat[6][3]; 
0 1 2 
0 e o e 
1 o e o 
2 e o e 
3 o e o 
4 e o e 
5 o e o
Arrays - 3D
Address of Variables 
● int x = 10; //value of x is 10 
● address of variable x is &x 
x 
10 
0x7fff4d84231c 
Variable Name 
Data/Content 
Address of variable
Demo #7 
Print the value and address of a float
Pointers 
Pointer is a variable that contains memory 
address. 
ptr 
0x7fff4d84231c 
p 
0x7fff01f8239c 
f 
0x00abcd12209
ptr 
0x7fff4d84231c 
p 
f 
0x243f01f8239a 0x00abcd12209 
10 
0x7fff4d84231c 
s 
0x243f01f8239a 
0.3 
0x00abcd12209
Demo #8 
&x returns the 
address of 
variable x
Pointer Dereferencing 
int *ptr; 
ptr = &x; 
cout<<ptr; 
cout<<*ptr; 
Pointer Declaration 
Making ptr point to x (x MUST be int) 
Will print address of x 
Will print the value stored at x 
6 
0x7fff4d84231c 
ptr 
x
Pointer Dereferencing 
*ptr returns the value stored at the memory 
location pointed to by ptr
Demo #9 
➔ Show and explain 9.cpp 
➔ Ask them to reproduce the code without looking
NULL Pointer 
int *ptr = NULL; //good coding practice 
ptr
Pointer to Pointer 
int x = 10; 
int *p = &x; 
int **q = &p; 
q 
0x32 
0x74 
p 
0x66 
0x32 
x 
10 
0x66
Arrays as pointers 
int arr[7]; 
Array Index 
Data 
arr 
0 1 2 3 4 5 6 
- 22 - 33 - 44 - 55 - 66 - 77 - 88 
0014 0018 0022 0026 0030 0034 0038 
arr + 1 arr +2 arr + 6 
Address
0 1 2 3 4 5 6 
- 22 - 33 - 44 - 55 - 66 - 77 - 88 
0014 0018 0022 0026 0030 0034 0038 
arr[0] is same as *(arr + 0) is same as -22 
&(arr[0]) is same as (arr + 0) is same as 0014 
arr[1] is same as *(arr + 1) is same as -33 
&(arr[1]) is same as (arr + 1) is same as 0018 
arr[5] is same as *(arr + 5) is same as -77 
&(arr[5]) is same as (arr + 5) is same as 0034 
Array Index 
int arr[7] 
Address 
arr
To be continued ... 
● Dynamic memory allocation 
● C-style strings. 
● strcmp, strcat etc.

More Related Content

What's hot

detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
gourav kottawar
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
karmuhtam
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
ssuserd6b1fd
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
ssuserd6b1fd
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
Chaand Sheikh
 
Learn Function The Hard Way
Learn Function The Hard WayLearn Function The Hard Way
Learn Function The Hard Way
Iftekhar Mohammad
 
Arrays in c
Arrays in cArrays in c
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
Germán Küber
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2rohassanie
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++Allan Sun
 
Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++
NUST Stuff
 
C++ programming pattern
C++ programming patternC++ programming pattern
C++ programming pattern
Raushankumar550
 

What's hot (20)

detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
 
C++ examples &revisions
C++ examples &revisionsC++ examples &revisions
C++ examples &revisions
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
pointers 1
pointers 1pointers 1
pointers 1
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
Learn Function The Hard Way
Learn Function The Hard WayLearn Function The Hard Way
Learn Function The Hard Way
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++
 
Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++
 
C++ programming pattern
C++ programming patternC++ programming pattern
C++ programming pattern
 
Pointer
PointerPointer
Pointer
 

Similar to Lecture 2: arrays and pointers

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
pointers
pointerspointers
pointers
teach4uin
 
Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptx
happycocoman
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
NUST Stuff
 
C arrays
C arraysC arrays
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
AntareepMajumder
 
Pointer
PointerPointer
Pointer
Fahuda E
 
Arrays 06.ppt
Arrays 06.pptArrays 06.ppt
Arrays 06.ppt
ahtishamtariq511
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
ShivamChaturvedi67
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
minal kumar soni
 
array 2 (1)_merged.pdf
array  2 (1)_merged.pdfarray  2 (1)_merged.pdf
array 2 (1)_merged.pdf
PradiptaPaul7
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
arjurakibulhasanrrr7
 
20.C++Pointer.pptx
20.C++Pointer.pptx20.C++Pointer.pptx
20.C++Pointer.pptx
AtharvPotdar2
 
Pointers
PointersPointers
Pointers
NabishaAK
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
FareedIhsas
 
Pointer in C
Pointer in CPointer in C
Pointer in C
bipchulabmki
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
Dhiviya Rose
 
Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]
Abdullah khawar
 

Similar to Lecture 2: arrays and pointers (20)

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
pointers
pointerspointers
pointers
 
Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Advanced C - Part 3
 
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptx
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
 
C arrays
C arraysC arrays
C arrays
 
Pointers
PointersPointers
Pointers
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
Pointer
PointerPointer
Pointer
 
Arrays 06.ppt
Arrays 06.pptArrays 06.ppt
Arrays 06.ppt
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
array 2 (1)_merged.pdf
array  2 (1)_merged.pdfarray  2 (1)_merged.pdf
array 2 (1)_merged.pdf
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
20.C++Pointer.pptx
20.C++Pointer.pptx20.C++Pointer.pptx
20.C++Pointer.pptx
 
Pointers
PointersPointers
Pointers
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
 
Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]
 

More from Vivek Bhargav

Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sorting
Vivek Bhargav
 
Lecture 11.1 : heaps
Lecture 11.1 :  heapsLecture 11.1 :  heaps
Lecture 11.1 : heaps
Vivek Bhargav
 
Lecture 10 : trees - 2
Lecture 10 : trees - 2Lecture 10 : trees - 2
Lecture 10 : trees - 2
Vivek Bhargav
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basics
Vivek Bhargav
 
Lecture 7 & 8: Stack & queue
Lecture 7 & 8: Stack  & queueLecture 7 & 8: Stack  & queue
Lecture 7 & 8: Stack & queue
Vivek Bhargav
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
Vivek Bhargav
 
Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithms
Vivek Bhargav
 
Lecture 4: Functions
Lecture 4: FunctionsLecture 4: Functions
Lecture 4: Functions
Vivek Bhargav
 
Lecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory AllocationLecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory Allocation
Vivek Bhargav
 
Lecture 1: basic syntax
Lecture 1: basic syntaxLecture 1: basic syntax
Lecture 1: basic syntax
Vivek Bhargav
 

More from Vivek Bhargav (10)

Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sorting
 
Lecture 11.1 : heaps
Lecture 11.1 :  heapsLecture 11.1 :  heaps
Lecture 11.1 : heaps
 
Lecture 10 : trees - 2
Lecture 10 : trees - 2Lecture 10 : trees - 2
Lecture 10 : trees - 2
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basics
 
Lecture 7 & 8: Stack & queue
Lecture 7 & 8: Stack  & queueLecture 7 & 8: Stack  & queue
Lecture 7 & 8: Stack & queue
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
 
Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithms
 
Lecture 4: Functions
Lecture 4: FunctionsLecture 4: Functions
Lecture 4: Functions
 
Lecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory AllocationLecture 3: Strings and Dynamic Memory Allocation
Lecture 3: Strings and Dynamic Memory Allocation
 
Lecture 1: basic syntax
Lecture 1: basic syntaxLecture 1: basic syntax
Lecture 1: basic syntax
 

Recently uploaded

Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 

Recently uploaded (20)

Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 

Lecture 2: arrays and pointers

  • 1. Placement Preparation Arrays & Pointers Shobhit Chaurasia B.Tech, CSE
  • 2. Target Audience People who have no prior coding experience, didn’t take CS101 seriously but want to learn some basics of coding quickly. If you know how write a program to sum up numbers in an array, and you DO NOT faint on seeing int ***ptr, then please don’t your waste time here; this tutorial is not for you.
  • 3. Data types ● int : -1000, -5, 0, 10, 2014 ● char : a, @, + ● float : -10.35, 2.578 ● bool : True/False
  • 4. More Data types ● Array - {1,2,3,4} ● String - “Ghissu” ● Pointers
  • 5. Arrays ● Array is a collection of objects.
  • 6. Arrays - 1D ● int test[10]; // space for 10 ints ● 0-based indexing ● Index from 0 to (size - 1)
  • 8. Demo #1 Store first 10 +ve integers in an array and print them.
  • 9. Demo #2 Sum up all the numbers in an array.
  • 10. Demo #3 Find the max. number in an array.
  • 11. Demo #4 Reverse the contents of an array. int arr[10]={1,2,3,4,5,6,7,8,9,10};
  • 12. Arrays - 2D (Matrix) ● int test_score[x][y] Row Index Column Index int test_score[10][4]
  • 13. Demo #5 Output contents of a 2D int array.
  • 14. Demo #6 char mat[6][3]; 0 1 2 0 e o e 1 o e o 2 e o e 3 o e o 4 e o e 5 o e o
  • 16. Address of Variables ● int x = 10; //value of x is 10 ● address of variable x is &x x 10 0x7fff4d84231c Variable Name Data/Content Address of variable
  • 17. Demo #7 Print the value and address of a float
  • 18. Pointers Pointer is a variable that contains memory address. ptr 0x7fff4d84231c p 0x7fff01f8239c f 0x00abcd12209
  • 19. ptr 0x7fff4d84231c p f 0x243f01f8239a 0x00abcd12209 10 0x7fff4d84231c s 0x243f01f8239a 0.3 0x00abcd12209
  • 20.
  • 21. Demo #8 &x returns the address of variable x
  • 22. Pointer Dereferencing int *ptr; ptr = &x; cout<<ptr; cout<<*ptr; Pointer Declaration Making ptr point to x (x MUST be int) Will print address of x Will print the value stored at x 6 0x7fff4d84231c ptr x
  • 23. Pointer Dereferencing *ptr returns the value stored at the memory location pointed to by ptr
  • 24. Demo #9 ➔ Show and explain 9.cpp ➔ Ask them to reproduce the code without looking
  • 25. NULL Pointer int *ptr = NULL; //good coding practice ptr
  • 26. Pointer to Pointer int x = 10; int *p = &x; int **q = &p; q 0x32 0x74 p 0x66 0x32 x 10 0x66
  • 27. Arrays as pointers int arr[7]; Array Index Data arr 0 1 2 3 4 5 6 - 22 - 33 - 44 - 55 - 66 - 77 - 88 0014 0018 0022 0026 0030 0034 0038 arr + 1 arr +2 arr + 6 Address
  • 28. 0 1 2 3 4 5 6 - 22 - 33 - 44 - 55 - 66 - 77 - 88 0014 0018 0022 0026 0030 0034 0038 arr[0] is same as *(arr + 0) is same as -22 &(arr[0]) is same as (arr + 0) is same as 0014 arr[1] is same as *(arr + 1) is same as -33 &(arr[1]) is same as (arr + 1) is same as 0018 arr[5] is same as *(arr + 5) is same as -77 &(arr[5]) is same as (arr + 5) is same as 0034 Array Index int arr[7] Address arr
  • 29. To be continued ... ● Dynamic memory allocation ● C-style strings. ● strcmp, strcat etc.