SlideShare a Scribd company logo
Pointers in C C++ Spring 2000  Arrays
Pointers ,[object Object],C++ Spring 2000  Arrays int foo; int *x; foo = 123; x = &foo; foo x 123 3 ... ... MEMORY 0 1 2 3 4 5 81345 81346 81347 Address
Pointers ,[object Object],[object Object],C++ Spring 2000  Arrays “ the int x points to”
Pointers ,[object Object],&foo   means “the address of foo” foo int foo; foo = 123; x = &foo; 123 ... ... MEMORY 0 1 2 3 4 5 Address
Assigning a value to a  dereferenced  pointer ,[object Object],C++ Spring 2000  Arrays int *x; *x=3; int foo; int *x; x = &foo; *x=3; ERROR!!! x doesn’t point to anything!!! this is fine x points to foo
Pointers to anything ,[object Object],[object Object],[object Object],C++ Spring 2000  Arrays x some  int some  *int some  int y z some  double
Pointer arithmetic ,[object Object],[object Object],C++ Spring 2000  Arrays int a[5]; a[0]  a[1]  a[2]  a[3]  a[4] int *ptr = a; *ptr *(ptr+2) *(ptr+4)
Operations on Pointers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C++ Spring 2000  Arrays
Pointer arithmetic ,[object Object],[object Object],[object Object],C++ Spring 2000  Arrays
Q&A ,[object Object],[object Object],[object Object],[object Object],C++ Spring 2000  Arrays
Pointers and Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],C++ Spring 2000  Arrays x  is “the address of  a[2]  ”
Printing an array  using Pointer ,[object Object],[object Object],[object Object],[object Object],[object Object],C++ Spring 2000  Arrays void print_array(int  *a , int len) { for (int i=0;i<len;i++)  cout << &quot;[&quot; << i << &quot;] = &quot;  <<  *a++  << endl; } pointer version array version
Q&A ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C++ Spring 2000  Arrays
Q&A ,[object Object],[object Object],C++ Spring 2000  Arrays
[object Object],C++ Spring 2000  Arrays
Call by Value ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Address (2 bytes) 65514 65515 65516 65517 65518 65519 65520 65521 65522 65523 65524 65525 a 4 b 4 8 main myFunc
Call by Reference ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Data Word Size  1 byte (assume) Address Word Size (2 bytes) 65514 65515 65516 65517 65518 65519 65520 65521 65522 65523 65524 65525 a 4 main myFunc 8 b 65520
Passing pointers as parameters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C++ Spring 2000  Arrays
Pointer Parameters ,[object Object],[object Object],[object Object],C++ Spring 2000  Arrays
Q&A ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C++ Spring 2000  Arrays
Pointers and String ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pointers and String ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pointers to Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pointer as Structure Member ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],NULL a b c a.data = 1; a.next->data = 2; /* b.data =2 */ a.next->next->data = 3; /* c.data = 3 */ c.next = (struct node *) malloc(sizeof(struct node)); ……
Pointers+(2)

More Related Content

What's hot

10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
웅식 전
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
tech4us
 

What's hot (20)

Pointers in C
Pointers in CPointers in C
Pointers in C
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
C Pointers
C PointersC Pointers
C Pointers
 
pointers
pointerspointers
pointers
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
 
Pointer
PointerPointer
Pointer
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
Pointers
PointersPointers
Pointers
 
This pointer
This pointerThis pointer
This pointer
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Pointers
PointersPointers
Pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 

Viewers also liked

Smart Pointer in C++
Smart Pointer in C++Smart Pointer in C++
Smart Pointer in C++
永泉 韩
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
Sahithi Naraparaju
 

Viewers also liked (20)

Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
C++ Pointers
C++ PointersC++ Pointers
C++ Pointers
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Smart Pointer in C++
Smart Pointer in C++Smart Pointer in C++
Smart Pointer in C++
 
[C언어의정석] ch7 포인터(pointer)
[C언어의정석] ch7 포인터(pointer)[C언어의정석] ch7 포인터(pointer)
[C언어의정석] ch7 포인터(pointer)
 
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++
 
Intro to C++ Basic
Intro to C++ BasicIntro to C++ Basic
Intro to C++ Basic
 
C LANGUAGE - BESTECH SOLUTIONS
C LANGUAGE - BESTECH SOLUTIONSC LANGUAGE - BESTECH SOLUTIONS
C LANGUAGE - BESTECH SOLUTIONS
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Pointers
PointersPointers
Pointers
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
 
C pointer
C pointerC pointer
C pointer
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
System of linear equation - SLE
System of linear equation - SLESystem of linear equation - SLE
System of linear equation - SLE
 
C program to write c program without using main function
C program to write c program without using main functionC program to write c program without using main function
C program to write c program without using main function
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 

Similar to Pointers+(2)

C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
Amit Kapoor
 

Similar to Pointers+(2) (20)

pointers 1
pointers 1pointers 1
pointers 1
 
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptx
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
C programming
C programmingC programming
C programming
 
Pointers.pdf
Pointers.pdfPointers.pdf
Pointers.pdf
 
Chapter5.pptx
Chapter5.pptxChapter5.pptx
Chapter5.pptx
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
Ch 7-pointers
Ch 7-pointersCh 7-pointers
Ch 7-pointers
 
Pointers
PointersPointers
Pointers
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Pointers
PointersPointers
Pointers
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
 

Recently uploaded

Recently uploaded (20)

Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 

Pointers+(2)

  • 1. Pointers in C C++ Spring 2000 Arrays
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.