SlideShare a Scribd company logo
1 of 29
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 languagegourav kottawar
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3karmuhtam
 
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
 
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
 

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 Arrays Pointers Placement Preparation Coding Basics

Similar to Arrays Pointers Placement Preparation Coding Basics (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 : sortingVivek Bhargav
 
Lecture 11.1 : heaps
Lecture 11.1 :  heapsLecture 11.1 :  heaps
Lecture 11.1 : heapsVivek Bhargav
 
Lecture 10 : trees - 2
Lecture 10 : trees - 2Lecture 10 : trees - 2
Lecture 10 : trees - 2Vivek Bhargav
 
Lecture 9: Binary tree basics
Lecture 9: Binary tree basicsLecture 9: Binary tree basics
Lecture 9: Binary tree basicsVivek Bhargav
 
Lecture 7 & 8: Stack & queue
Lecture 7 & 8: Stack  & queueLecture 7 & 8: Stack  & queue
Lecture 7 & 8: Stack & queueVivek Bhargav
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked listVivek Bhargav
 
Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsVivek Bhargav
 
Lecture 4: Functions
Lecture 4: FunctionsLecture 4: Functions
Lecture 4: FunctionsVivek 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 AllocationVivek Bhargav
 
Lecture 1: basic syntax
Lecture 1: basic syntaxLecture 1: basic syntax
Lecture 1: basic syntaxVivek 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

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 

Recently uploaded (20)

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 

Arrays Pointers Placement Preparation Coding Basics

  • 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.