SlideShare a Scribd company logo
CS110 - Intro. To Computing
Pointers !!!!!!!
Lab - 5
• Last Monday’s batch - come today
• Last Friday’s batch - class cancelled
because of server problem - come
tomorrow - 2 PM
Let us Revise
• What are these?
– int *p, *q, *r;

• What are these?
– int a,b,c;
Let us Revise
• What are these?
– int *p, *q, *r; - p, q, r are address storing
integer variables

• What are these?
– int a,b,c; - a, b, c are names of integer
variables
Let us Revise
• What are these?
– int *p, *q, *r;
– *p = 5; Content of address p is 5.

• What are these?
– int a,b,c;
– &a = 0x1000; Address storing variable
named a is 0x1000
Let us Revise
• Given int *p;
– &p is wrong - It means address of address.

• Given int b;
– *b is wrong - it means value of value
Let us Revise
• Function Calls
• Given int my_func(int *p);
• This can be called as follows:
– int a,b; b = my_func(&a);
– int *a; int b; b = my_func(a);
– Int *a, *b; *b = my_func(a);
Let us Revise
• Function Calls
• Given int my_func(int p);
• This can be called as follows:
– int a,b; b = my_func(a);
– int *a; int b; b = my_func(*a);
– Int *a, *b; *b = my_func(*a);
Let us Revise
• Arrays
– int a[100];

• Now a is a pointer to the start of the
location - address of a variable
• a[5] is a value of the 5th location - name
of a variable
Passing Arrays
• All our previous functions we passed
only single values - not arrays.
• In C array is passed “by reference”.
– Implication
• If you change the value inside the function it
gets reflected in the calling function.
Example
void modify(int a[]) {
int count;
printf(“n From the function, after modifying the values:n”);
for (count = 0; count <= 2; count++) {
a[count] = -9;
printf(“a[%d] = %dn”, count, a[count]);
}
return;
}
main() {
int count, a[3];
void modify(int a[]);
printf(“n From main, before calling the
functionn”);
for (count = 0; count <= 2; ++count) {
a[count] = count + 1;
printf(“a[%d] = %dn”,count, a[count]);
}
modify();
printf(“n From main, after calling the
functionn”);
for (count = 0; count <= 2; ++count) {
printf(“a[%d] = %dn”,count, a[count]);
}
}
From main, before calling the function:
a[0] = 1
a[1] = 2
a[2] = 3

main() {
int count, a[3];
void modify(int a[]);
printf(“n From main, before calling the
functionn”);
for (count = 0; count <= 2; ++count) {
a[count] = count + 1;
printf(“a[%d] = %dn”,count, a[count]);
}
modify();
printf(“n From main, before calling the
functionn”);
for (count = 0; count <= 2; ++count) {
printf(“a[%d] = %dn”,count, a[count]);
}
}
Example
void modify(int a[]) {
int count;
printf(“n From the function, after modifying the values:n”);
for (count = 0; count <= 2; count++) {
a[count] = -9;
printf(“a[%d] = %dn”, count, a[count]);
}
return;
}

From the function, after modifying the values:
a[0] = -9
a[1] = -9
a[2] = -9
main() {
int count, a[3];
void modify(int a[]);
printf(“n From main, before calling the
functionn”);
for (count = 0; count <= 2; ++count) {
a[count] = count + 1;
printf(“a[%d] = %dn”,count, a[count]);
}
modify(a);
printf(“n From main, after calling the
functionn”);
for (count = 0; count <= 2; ++count) {
printf(“a[%d] = %dn”,count, a[count]);
}
From main, after calling the function:
}

a[0] = -9
a[1] = -9
a[2] = -9
Multidimensional Arrays
main() {
int *nrows, *ncols;
int a[30][30];
void readinput(int a[][30], int *,int *);
void writeoutput(int a[][30], int, int);
readinput(a,nrows,ncols);
printf(“n Number of rows %dn”,*nrows);
printf(“n Number of columns %dn”,*ncols);
writeoutput(a,*nows,*ncols);
}
void readinput(int a[][30], int *m, int *n) {
int i, j;
printf(“Number of rowsn”);
scanf(“%d”,m);
printf(“Number of columnsn”);
scanf(“%d”,n);
for (i = 0; i < *m; i++)
for (j = 0; j < *n; j++)
scanf(“%d”, &a[i][j])
}
void writeoutput(int a[][30], int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++)
printf(“%4d”, a[i][j]);
printf(“n”);
}
return;
}
int u = 3;
int v;
int *pu;
int *pv;
pu = &u;
v = *pu;
pv = &v;
When you print * and & versions of them? What happens?

More Related Content

What's hot

Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++
NUST Stuff
 
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
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
C programming function
C  programming functionC  programming function
C programming function
argusacademy
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
NUST Stuff
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Sachin Sharma
 
Functions in c
Functions in cFunctions in c
Functions in c
Innovative
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Nikhil Pandit
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
Unviersity of balochistan quetta
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
AnkitaSharma463389
 
Functions in C
Functions in CFunctions in C
Functions in C
Princy Nelson
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
HNDE Labuduwa Galle
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
Lakshmi Sarvani Videla
 
Functions in c++,
Functions in c++,Functions in c++,
Functions in c++,
Padma Kannan
 
Functions
FunctionsFunctions
Functions
PralhadKhanal1
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 

What's hot (20)

Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference 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++
 
Call by value
Call by valueCall by value
Call by value
 
C programming function
C  programming functionC  programming function
C programming function
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Lecture#9 Arrays in c++
Lecture#9 Arrays in c++Lecture#9 Arrays in c++
Lecture#9 Arrays in c++
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
functions of C++
functions of C++functions of C++
functions of C++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
Functions in C
Functions in CFunctions in C
Functions in C
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
 
Function Pointer in C
Function Pointer in CFunction Pointer in C
Function Pointer in C
 
Functions in c++,
Functions in c++,Functions in c++,
Functions in c++,
 
Functions
FunctionsFunctions
Functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 

Viewers also liked

Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec15-CS110 Computational Engineering
Lec15-CS110 Computational EngineeringLec15-CS110 Computational Engineering
Lec15-CS110 Computational Engineering
Sri Harsha Pamu
 

Viewers also liked (7)

Lec14-CS110 Computational Engineering
Lec14-CS110 Computational EngineeringLec14-CS110 Computational Engineering
Lec14-CS110 Computational Engineering
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational Engineering
 
Lec10-CS110 Computational Engineering
Lec10-CS110 Computational EngineeringLec10-CS110 Computational Engineering
Lec10-CS110 Computational Engineering
 
Lec19-CS110 Computational Engineering
Lec19-CS110 Computational EngineeringLec19-CS110 Computational Engineering
Lec19-CS110 Computational Engineering
 
Lec12-CS110 Computational Engineering
Lec12-CS110 Computational EngineeringLec12-CS110 Computational Engineering
Lec12-CS110 Computational Engineering
 
Lec15-CS110 Computational Engineering
Lec15-CS110 Computational EngineeringLec15-CS110 Computational Engineering
Lec15-CS110 Computational Engineering
 

Similar to Lec21-CS110 Computational Engineering

46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
Rubal Bansal
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
LOVELY PROFESSIONAL UNIVERSITY
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
khush_boo31
 
Array Cont
Array ContArray Cont
L4 functions
L4 functionsL4 functions
L4 functions
mondalakash2012
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 
FUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxFUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptx
DeepasCSE
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
ssuserd6b1fd
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
GkhanGirgin3
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
Han Lee
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Array
ArrayArray
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
ShivamChaturvedi67
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
vanshhans21102005
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
Sreedhar Chowdam
 
3 Function & Storage Class.pptx
3 Function & Storage Class.pptx3 Function & Storage Class.pptx
3 Function & Storage Class.pptx
aarockiaabinsAPIICSE
 

Similar to Lec21-CS110 Computational Engineering (20)

46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
Array Cont
Array ContArray Cont
Array Cont
 
L4 functions
L4 functionsL4 functions
L4 functions
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
FUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxFUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptx
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Array
ArrayArray
Array
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
3 Function & Storage Class.pptx
3 Function & Storage Class.pptx3 Function & Storage Class.pptx
3 Function & Storage Class.pptx
 

More from Sri Harsha Pamu

Lec13
Lec13Lec13
Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringLec06-CS110 Computational Engineering
Lec06-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational Engineering
Sri Harsha Pamu
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
Sri Harsha Pamu
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational Engineering
Sri Harsha Pamu
 
Android..imp google
Android..imp googleAndroid..imp google
Android..imp google
Sri Harsha Pamu
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability study
Sri Harsha Pamu
 
Android gui framework
Android gui frameworkAndroid gui framework
Android gui framework
Sri Harsha Pamu
 
Hackernote on gsoc
Hackernote on gsocHackernote on gsoc
Hackernote on gsoc
Sri Harsha Pamu
 
Boot2Gecko Hackernote
Boot2Gecko HackernoteBoot2Gecko Hackernote
Boot2Gecko Hackernote
Sri Harsha Pamu
 

More from Sri Harsha Pamu (16)

Lec13
Lec13Lec13
Lec13
 
Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational Engineering
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational Engineering
 
Lec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringLec06-CS110 Computational Engineering
Lec06-CS110 Computational Engineering
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational Engineering
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational Engineering
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational Engineering
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational Engineering
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational Engineering
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational Engineering
 
Android..imp google
Android..imp googleAndroid..imp google
Android..imp google
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability study
 
Android gui framework
Android gui frameworkAndroid gui framework
Android gui framework
 
Hackernote on gsoc
Hackernote on gsocHackernote on gsoc
Hackernote on gsoc
 
Boot2Gecko Hackernote
Boot2Gecko HackernoteBoot2Gecko Hackernote
Boot2Gecko Hackernote
 

Recently uploaded

Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 

Recently uploaded (20)

Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 

Lec21-CS110 Computational Engineering

  • 1. CS110 - Intro. To Computing Pointers !!!!!!!
  • 2. Lab - 5 • Last Monday’s batch - come today • Last Friday’s batch - class cancelled because of server problem - come tomorrow - 2 PM
  • 3. Let us Revise • What are these? – int *p, *q, *r; • What are these? – int a,b,c;
  • 4. Let us Revise • What are these? – int *p, *q, *r; - p, q, r are address storing integer variables • What are these? – int a,b,c; - a, b, c are names of integer variables
  • 5. Let us Revise • What are these? – int *p, *q, *r; – *p = 5; Content of address p is 5. • What are these? – int a,b,c; – &a = 0x1000; Address storing variable named a is 0x1000
  • 6. Let us Revise • Given int *p; – &p is wrong - It means address of address. • Given int b; – *b is wrong - it means value of value
  • 7. Let us Revise • Function Calls • Given int my_func(int *p); • This can be called as follows: – int a,b; b = my_func(&a); – int *a; int b; b = my_func(a); – Int *a, *b; *b = my_func(a);
  • 8. Let us Revise • Function Calls • Given int my_func(int p); • This can be called as follows: – int a,b; b = my_func(a); – int *a; int b; b = my_func(*a); – Int *a, *b; *b = my_func(*a);
  • 9. Let us Revise • Arrays – int a[100]; • Now a is a pointer to the start of the location - address of a variable • a[5] is a value of the 5th location - name of a variable
  • 10. Passing Arrays • All our previous functions we passed only single values - not arrays. • In C array is passed “by reference”. – Implication • If you change the value inside the function it gets reflected in the calling function.
  • 11. Example void modify(int a[]) { int count; printf(“n From the function, after modifying the values:n”); for (count = 0; count <= 2; count++) { a[count] = -9; printf(“a[%d] = %dn”, count, a[count]); } return; }
  • 12. main() { int count, a[3]; void modify(int a[]); printf(“n From main, before calling the functionn”); for (count = 0; count <= 2; ++count) { a[count] = count + 1; printf(“a[%d] = %dn”,count, a[count]); } modify(); printf(“n From main, after calling the functionn”); for (count = 0; count <= 2; ++count) { printf(“a[%d] = %dn”,count, a[count]); } }
  • 13. From main, before calling the function: a[0] = 1 a[1] = 2 a[2] = 3 main() { int count, a[3]; void modify(int a[]); printf(“n From main, before calling the functionn”); for (count = 0; count <= 2; ++count) { a[count] = count + 1; printf(“a[%d] = %dn”,count, a[count]); } modify(); printf(“n From main, before calling the functionn”); for (count = 0; count <= 2; ++count) { printf(“a[%d] = %dn”,count, a[count]); } }
  • 14. Example void modify(int a[]) { int count; printf(“n From the function, after modifying the values:n”); for (count = 0; count <= 2; count++) { a[count] = -9; printf(“a[%d] = %dn”, count, a[count]); } return; } From the function, after modifying the values: a[0] = -9 a[1] = -9 a[2] = -9
  • 15. main() { int count, a[3]; void modify(int a[]); printf(“n From main, before calling the functionn”); for (count = 0; count <= 2; ++count) { a[count] = count + 1; printf(“a[%d] = %dn”,count, a[count]); } modify(a); printf(“n From main, after calling the functionn”); for (count = 0; count <= 2; ++count) { printf(“a[%d] = %dn”,count, a[count]); } From main, after calling the function: } a[0] = -9 a[1] = -9 a[2] = -9
  • 16. Multidimensional Arrays main() { int *nrows, *ncols; int a[30][30]; void readinput(int a[][30], int *,int *); void writeoutput(int a[][30], int, int); readinput(a,nrows,ncols); printf(“n Number of rows %dn”,*nrows); printf(“n Number of columns %dn”,*ncols); writeoutput(a,*nows,*ncols); }
  • 17. void readinput(int a[][30], int *m, int *n) { int i, j; printf(“Number of rowsn”); scanf(“%d”,m); printf(“Number of columnsn”); scanf(“%d”,n); for (i = 0; i < *m; i++) for (j = 0; j < *n; j++) scanf(“%d”, &a[i][j]) }
  • 18. void writeoutput(int a[][30], int row, int col) { int i, j; for (i = 0; i < row; i++) { for (j = 0; j < col; j++) printf(“%4d”, a[i][j]); printf(“n”); } return; }
  • 19. int u = 3; int v; int *pu; int *pv; pu = &u; v = *pu; pv = &v; When you print * and & versions of them? What happens?