SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
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?

Weitere ähnliche Inhalte

Was ist angesagt?

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 valueDharani G
 
C programming function
C  programming functionC  programming function
C programming functionargusacademy
 
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++ PPT03062679929
 
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 in c
Functions in cFunctions in c
Functions in cInnovative
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 

Was ist angesagt? (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++
 

Andere mochten auch

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

Andere mochten auch (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
 

Ähnlich wie Lec21-CS110 Computational Engineering

46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1AmIt Prasad
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#khush_boo31
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptxNagasaiT
 
FUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxFUNCTIONS, CLASSES AND OBJECTS.pptx
FUNCTIONS, CLASSES AND OBJECTS.pptxDeepasCSE
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
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
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxvanshhans21102005
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementSreedhar Chowdam
 

Ähnlich wie 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
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
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...
 
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
 

Mehr von Sri Harsha Pamu

Lec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringLec09-CS110 Computational Engineering
Lec09-CS110 Computational EngineeringSri Harsha Pamu
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringSri Harsha Pamu
 
Lec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringLec07-CS110 Computational Engineering
Lec07-CS110 Computational EngineeringSri Harsha Pamu
 
Lec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringLec06-CS110 Computational Engineering
Lec06-CS110 Computational EngineeringSri Harsha Pamu
 
Lec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringLec04-CS110 Computational Engineering
Lec04-CS110 Computational EngineeringSri Harsha Pamu
 
Lec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringLec03-CS110 Computational Engineering
Lec03-CS110 Computational EngineeringSri Harsha Pamu
 
Lec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringLec02-CS110 Computational Engineering
Lec02-CS110 Computational EngineeringSri Harsha Pamu
 
Lec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringLec01-CS110 Computational Engineering
Lec01-CS110 Computational EngineeringSri Harsha Pamu
 
Lec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringLec1- CS110 Computational Engineering
Lec1- CS110 Computational EngineeringSri Harsha Pamu
 
Lec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringLec25-CS110 Computational Engineering
Lec25-CS110 Computational EngineeringSri Harsha Pamu
 
Android vulnerability study
Android vulnerability studyAndroid vulnerability study
Android vulnerability studySri Harsha Pamu
 

Mehr von 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
 

Kürzlich hochgeladen

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Kürzlich hochgeladen (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

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?