SlideShare a Scribd company logo
1 of 2
Download to read offline
i. Again note that x is in the main function (it's a word - at some location - in the memory area
associated only with the main function). You want to change the value of x, but you need to do that
work in the function f3. f3 has its own memory area, but it can't directly use the variables in the
main function's memory area (where x lives). BUT, in f3 you DO have the address of where x is
located in the main function's memory area. To emphasize, x is in the main function, x_address is
in function f3. You have that address of x inside f3 because it was copied ("passed") into
x_address when in the call to f3 you passed &x as an argument. So to access x (either to get it or
to set it) in f3 you have to dereference the x_address. Again, by dereferencing the x_address in
the f3 code, you are working (in f3) with the memory word x which is only in the main function.
j. Important aside: It is important to recognize that using addresses (pointers) is not directly
dependent on whether or not you are using functions. If you had both x and x_address declared in
a main function and were to put the address of x into the variable x_address in the main function
code with the statement x_address = &x; , then the following two lines are absolutely equivalent in
the main function and you could use either: x = x + 4; and *x_address = *x_address + 4;
k. Why do we go through all this rigamarole with addresses when we want to change a value in a
function? Because in C (and many other computer languages) argument values are only ever
**passed into** (copied into) function parameters. Nothing (!!) is EVER "passed back". So if you
just copied in x to y, as in the earlier steps of this lab, you could change y all you wanted in the
function... and x in the main function would still be the same old x it always was. You would only
be changing the COPY of x in f3 (y would be the copy as you used it in the earlier steps 6 or 7).
So, if we want a change to be made to a value in the main function, we pass the address of
WHERE we want the change made (in the main function) to the helper function (such as f3); the
helper function accesses that address/location in the main function's memory, which it does have
[of course it does, we passed that address to the function] and the called function (f3) makes the
change there (in the calling main function). Note also that using a return statement to bring
something "back" is a completely separate issue, and it can only return a single value - whereas in
a great many cases far more than one item from a function is wanted. In those cases, such as you
did in this step and will also do in the step below, you have to pass an address and then use
dereferencing in the called function.
l.Now that you've seen how to pass in an address of a variable to a function and in that function
use that address to make a change to the variable, back in the calling (main in this case) function,
you can comment all the preceding function calling and write and call another void function f4
which has three parameters. The first, an integer variable named y, will be passed the initial
number x from the main function, as seen above. The other two parameters will receive addresses
from the call. The second parameter, named addr1, will be used to receive the address of a
variable named num_of_tens which you will declare in the main function. The third parameter,
named addr2, will be used to receive the address of a variable named remainder also declared in
the main function . In the main function, the value will first be set for x, as above, and then f4 is to
be called, passing it the value of x and the value of the address of num_of_tens (written as
&num_of_tens) and the value of the address of remainder (written as &remainder). Neither
num_of_tens or remainder have had anything put into them at the point where f4 is called. In fact,
nothing in the main function will set them. f4 will, using the code you wrote earlier, determine the
number of 10s in y (copied from x) and the remainder when y is divided by 10. By dereferencing
addr1 and addr2, f4 will then set these calculated values into the variables num_of_tens and
remainder (they are both in the main function's memory area or as we often term in "they are in
the main function") ... and then f4 will quit. Nothing is returned, nothing is "sent back". You passed
in two addresses, made changes at those two addresses, and then the function is finished and
control passes back to the main function. Immediately after the call to f4, in the main function write
code so that it will print out the values of num_of_tens and remainder, properly labeled. Try this
with a few different initial numbers.
m.You final program should look like this. The user enters a number between 10 and 99
(validated), then the program calls the function f3 that gives both the quotient and the remainder of
a division by 10. The two values are printed out (not in the f3 function, but in the main program).

More Related Content

Similar to i Again note that x is in the main function its a word .pdf

User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in CRAJ KUMAR
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
functioninpython-1.pptx
functioninpython-1.pptxfunctioninpython-1.pptx
functioninpython-1.pptxSulekhJangra
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programmingnmahi96
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdfprasnt1
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptxzueZ3
 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxAaliyanShaikh
 
Handout # 6 pointers and recursion in c++
Handout # 6   pointers and recursion in c++Handout # 6   pointers and recursion in c++
Handout # 6 pointers and recursion in c++NUST Stuff
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdfNehaSpillai1
 
Functions in Python Syntax and working .
Functions in Python Syntax and working .Functions in Python Syntax and working .
Functions in Python Syntax and working .tarunsharmaug23
 

Similar to i Again note that x is in the main function its a word .pdf (20)

User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
 
2 Functions2.pptx
2 Functions2.pptx2 Functions2.pptx
2 Functions2.pptx
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
functioninpython-1.pptx
functioninpython-1.pptxfunctioninpython-1.pptx
functioninpython-1.pptx
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
Functions
Functions Functions
Functions
 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptx
 
Handout # 6 pointers and recursion in c++
Handout # 6   pointers and recursion in c++Handout # 6   pointers and recursion in c++
Handout # 6 pointers and recursion in c++
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdf
 
Functions in Python Syntax and working .
Functions in Python Syntax and working .Functions in Python Syntax and working .
Functions in Python Syntax and working .
 
Function in C++
Function in C++Function in C++
Function in C++
 

More from abdulahmad786

Which of the following statements is FALSE regarding immunit.pdf
Which of the following statements is FALSE regarding immunit.pdfWhich of the following statements is FALSE regarding immunit.pdf
Which of the following statements is FALSE regarding immunit.pdfabdulahmad786
 
What is the difference between using the post and get me.pdf
What is the difference between using the post and get me.pdfWhat is the difference between using the post and get me.pdf
What is the difference between using the post and get me.pdfabdulahmad786
 
The difference between the movement of carbohydrates and the.pdf
The difference between the movement of carbohydrates and the.pdfThe difference between the movement of carbohydrates and the.pdf
The difference between the movement of carbohydrates and the.pdfabdulahmad786
 
Un famoso jugador de baloncesto llamado Fabian James decide .pdf
Un famoso jugador de baloncesto llamado Fabian James decide .pdfUn famoso jugador de baloncesto llamado Fabian James decide .pdf
Un famoso jugador de baloncesto llamado Fabian James decide .pdfabdulahmad786
 
The issued share capital of Karnelli Pty Ltd consists of t.pdf
The issued share capital of Karnelli Pty Ltd consists of t.pdfThe issued share capital of Karnelli Pty Ltd consists of t.pdf
The issued share capital of Karnelli Pty Ltd consists of t.pdfabdulahmad786
 
subscribers in thousands in Albemarle County outside of Ch.pdf
subscribers in thousands in Albemarle County outside of Ch.pdfsubscribers in thousands in Albemarle County outside of Ch.pdf
subscribers in thousands in Albemarle County outside of Ch.pdfabdulahmad786
 
QUESTION Lets assume you are a treasurer of an internationa.pdf
QUESTION Lets assume you are a treasurer of an internationa.pdfQUESTION Lets assume you are a treasurer of an internationa.pdf
QUESTION Lets assume you are a treasurer of an internationa.pdfabdulahmad786
 
Respiratory pathwayDescribe the path of a molecule of oxygen.pdf
Respiratory pathwayDescribe the path of a molecule of oxygen.pdfRespiratory pathwayDescribe the path of a molecule of oxygen.pdf
Respiratory pathwayDescribe the path of a molecule of oxygen.pdfabdulahmad786
 
Project Bird species The OrdwayBirds data frame is a histor.pdf
Project Bird species The OrdwayBirds data frame is a histor.pdfProject Bird species The OrdwayBirds data frame is a histor.pdf
Project Bird species The OrdwayBirds data frame is a histor.pdfabdulahmad786
 
Problem 2 What is the effect of current capital stock K goi.pdf
Problem 2 What is the effect of current capital stock K goi.pdfProblem 2 What is the effect of current capital stock K goi.pdf
Problem 2 What is the effect of current capital stock K goi.pdfabdulahmad786
 
Deliverables that needs to be submitted on March 14 th 202.pdf
Deliverables that needs to be submitted on March 14 th  202.pdfDeliverables that needs to be submitted on March 14 th  202.pdf
Deliverables that needs to be submitted on March 14 th 202.pdfabdulahmad786
 
On April 1 2020 Mendoza Company a USbased company bor.pdf
On April 1 2020 Mendoza Company a USbased company bor.pdfOn April 1 2020 Mendoza Company a USbased company bor.pdf
On April 1 2020 Mendoza Company a USbased company bor.pdfabdulahmad786
 
Las iguanas marinas pueden permanecer ms tiempo bajo el ag.pdf
Las iguanas marinas pueden permanecer ms tiempo bajo el ag.pdfLas iguanas marinas pueden permanecer ms tiempo bajo el ag.pdf
Las iguanas marinas pueden permanecer ms tiempo bajo el ag.pdfabdulahmad786
 
Determine the value of xt in the steady state How would y.pdf
Determine the value of xt in the steady state How would y.pdfDetermine the value of xt in the steady state How would y.pdf
Determine the value of xt in the steady state How would y.pdfabdulahmad786
 
Metadata can best be described as which of the following .pdf
Metadata can best be described as which of the following   .pdfMetadata can best be described as which of the following   .pdf
Metadata can best be described as which of the following .pdfabdulahmad786
 
Cul de los siguientes tipos bsicos de formatos de diseo .pdf
Cul de los siguientes tipos bsicos de formatos de diseo .pdfCul de los siguientes tipos bsicos de formatos de diseo .pdf
Cul de los siguientes tipos bsicos de formatos de diseo .pdfabdulahmad786
 
6 Why is the PXxPXltx .pdf
6 Why is the PXxPXltx .pdf6 Why is the PXxPXltx .pdf
6 Why is the PXxPXltx .pdfabdulahmad786
 
Colton Cars Co issued 18 million of 5 5year bonds on J.pdf
Colton Cars Co issued 18 million of 5 5year bonds on J.pdfColton Cars Co issued 18 million of 5 5year bonds on J.pdf
Colton Cars Co issued 18 million of 5 5year bonds on J.pdfabdulahmad786
 
Fransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdf
Fransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdfFransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdf
Fransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdfabdulahmad786
 
Among cattle of the breed sortbroget dansk malkerace SDM.pdf
Among cattle of the breed sortbroget dansk malkerace SDM.pdfAmong cattle of the breed sortbroget dansk malkerace SDM.pdf
Among cattle of the breed sortbroget dansk malkerace SDM.pdfabdulahmad786
 

More from abdulahmad786 (20)

Which of the following statements is FALSE regarding immunit.pdf
Which of the following statements is FALSE regarding immunit.pdfWhich of the following statements is FALSE regarding immunit.pdf
Which of the following statements is FALSE regarding immunit.pdf
 
What is the difference between using the post and get me.pdf
What is the difference between using the post and get me.pdfWhat is the difference between using the post and get me.pdf
What is the difference between using the post and get me.pdf
 
The difference between the movement of carbohydrates and the.pdf
The difference between the movement of carbohydrates and the.pdfThe difference between the movement of carbohydrates and the.pdf
The difference between the movement of carbohydrates and the.pdf
 
Un famoso jugador de baloncesto llamado Fabian James decide .pdf
Un famoso jugador de baloncesto llamado Fabian James decide .pdfUn famoso jugador de baloncesto llamado Fabian James decide .pdf
Un famoso jugador de baloncesto llamado Fabian James decide .pdf
 
The issued share capital of Karnelli Pty Ltd consists of t.pdf
The issued share capital of Karnelli Pty Ltd consists of t.pdfThe issued share capital of Karnelli Pty Ltd consists of t.pdf
The issued share capital of Karnelli Pty Ltd consists of t.pdf
 
subscribers in thousands in Albemarle County outside of Ch.pdf
subscribers in thousands in Albemarle County outside of Ch.pdfsubscribers in thousands in Albemarle County outside of Ch.pdf
subscribers in thousands in Albemarle County outside of Ch.pdf
 
QUESTION Lets assume you are a treasurer of an internationa.pdf
QUESTION Lets assume you are a treasurer of an internationa.pdfQUESTION Lets assume you are a treasurer of an internationa.pdf
QUESTION Lets assume you are a treasurer of an internationa.pdf
 
Respiratory pathwayDescribe the path of a molecule of oxygen.pdf
Respiratory pathwayDescribe the path of a molecule of oxygen.pdfRespiratory pathwayDescribe the path of a molecule of oxygen.pdf
Respiratory pathwayDescribe the path of a molecule of oxygen.pdf
 
Project Bird species The OrdwayBirds data frame is a histor.pdf
Project Bird species The OrdwayBirds data frame is a histor.pdfProject Bird species The OrdwayBirds data frame is a histor.pdf
Project Bird species The OrdwayBirds data frame is a histor.pdf
 
Problem 2 What is the effect of current capital stock K goi.pdf
Problem 2 What is the effect of current capital stock K goi.pdfProblem 2 What is the effect of current capital stock K goi.pdf
Problem 2 What is the effect of current capital stock K goi.pdf
 
Deliverables that needs to be submitted on March 14 th 202.pdf
Deliverables that needs to be submitted on March 14 th  202.pdfDeliverables that needs to be submitted on March 14 th  202.pdf
Deliverables that needs to be submitted on March 14 th 202.pdf
 
On April 1 2020 Mendoza Company a USbased company bor.pdf
On April 1 2020 Mendoza Company a USbased company bor.pdfOn April 1 2020 Mendoza Company a USbased company bor.pdf
On April 1 2020 Mendoza Company a USbased company bor.pdf
 
Las iguanas marinas pueden permanecer ms tiempo bajo el ag.pdf
Las iguanas marinas pueden permanecer ms tiempo bajo el ag.pdfLas iguanas marinas pueden permanecer ms tiempo bajo el ag.pdf
Las iguanas marinas pueden permanecer ms tiempo bajo el ag.pdf
 
Determine the value of xt in the steady state How would y.pdf
Determine the value of xt in the steady state How would y.pdfDetermine the value of xt in the steady state How would y.pdf
Determine the value of xt in the steady state How would y.pdf
 
Metadata can best be described as which of the following .pdf
Metadata can best be described as which of the following   .pdfMetadata can best be described as which of the following   .pdf
Metadata can best be described as which of the following .pdf
 
Cul de los siguientes tipos bsicos de formatos de diseo .pdf
Cul de los siguientes tipos bsicos de formatos de diseo .pdfCul de los siguientes tipos bsicos de formatos de diseo .pdf
Cul de los siguientes tipos bsicos de formatos de diseo .pdf
 
6 Why is the PXxPXltx .pdf
6 Why is the PXxPXltx .pdf6 Why is the PXxPXltx .pdf
6 Why is the PXxPXltx .pdf
 
Colton Cars Co issued 18 million of 5 5year bonds on J.pdf
Colton Cars Co issued 18 million of 5 5year bonds on J.pdfColton Cars Co issued 18 million of 5 5year bonds on J.pdf
Colton Cars Co issued 18 million of 5 5year bonds on J.pdf
 
Fransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdf
Fransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdfFransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdf
Fransa hkmeti bte a veriyor RicardoBarro etkisi olmad.pdf
 
Among cattle of the breed sortbroget dansk malkerace SDM.pdf
Among cattle of the breed sortbroget dansk malkerace SDM.pdfAmong cattle of the breed sortbroget dansk malkerace SDM.pdf
Among cattle of the breed sortbroget dansk malkerace SDM.pdf
 

Recently uploaded

Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 

Recently uploaded (20)

Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 

i Again note that x is in the main function its a word .pdf

  • 1. i. Again note that x is in the main function (it's a word - at some location - in the memory area associated only with the main function). You want to change the value of x, but you need to do that work in the function f3. f3 has its own memory area, but it can't directly use the variables in the main function's memory area (where x lives). BUT, in f3 you DO have the address of where x is located in the main function's memory area. To emphasize, x is in the main function, x_address is in function f3. You have that address of x inside f3 because it was copied ("passed") into x_address when in the call to f3 you passed &x as an argument. So to access x (either to get it or to set it) in f3 you have to dereference the x_address. Again, by dereferencing the x_address in the f3 code, you are working (in f3) with the memory word x which is only in the main function. j. Important aside: It is important to recognize that using addresses (pointers) is not directly dependent on whether or not you are using functions. If you had both x and x_address declared in a main function and were to put the address of x into the variable x_address in the main function code with the statement x_address = &x; , then the following two lines are absolutely equivalent in the main function and you could use either: x = x + 4; and *x_address = *x_address + 4; k. Why do we go through all this rigamarole with addresses when we want to change a value in a function? Because in C (and many other computer languages) argument values are only ever **passed into** (copied into) function parameters. Nothing (!!) is EVER "passed back". So if you just copied in x to y, as in the earlier steps of this lab, you could change y all you wanted in the function... and x in the main function would still be the same old x it always was. You would only be changing the COPY of x in f3 (y would be the copy as you used it in the earlier steps 6 or 7). So, if we want a change to be made to a value in the main function, we pass the address of WHERE we want the change made (in the main function) to the helper function (such as f3); the helper function accesses that address/location in the main function's memory, which it does have [of course it does, we passed that address to the function] and the called function (f3) makes the change there (in the calling main function). Note also that using a return statement to bring something "back" is a completely separate issue, and it can only return a single value - whereas in a great many cases far more than one item from a function is wanted. In those cases, such as you did in this step and will also do in the step below, you have to pass an address and then use dereferencing in the called function. l.Now that you've seen how to pass in an address of a variable to a function and in that function use that address to make a change to the variable, back in the calling (main in this case) function, you can comment all the preceding function calling and write and call another void function f4 which has three parameters. The first, an integer variable named y, will be passed the initial number x from the main function, as seen above. The other two parameters will receive addresses from the call. The second parameter, named addr1, will be used to receive the address of a variable named num_of_tens which you will declare in the main function. The third parameter, named addr2, will be used to receive the address of a variable named remainder also declared in the main function . In the main function, the value will first be set for x, as above, and then f4 is to be called, passing it the value of x and the value of the address of num_of_tens (written as &num_of_tens) and the value of the address of remainder (written as &remainder). Neither num_of_tens or remainder have had anything put into them at the point where f4 is called. In fact, nothing in the main function will set them. f4 will, using the code you wrote earlier, determine the
  • 2. number of 10s in y (copied from x) and the remainder when y is divided by 10. By dereferencing addr1 and addr2, f4 will then set these calculated values into the variables num_of_tens and remainder (they are both in the main function's memory area or as we often term in "they are in the main function") ... and then f4 will quit. Nothing is returned, nothing is "sent back". You passed in two addresses, made changes at those two addresses, and then the function is finished and control passes back to the main function. Immediately after the call to f4, in the main function write code so that it will print out the values of num_of_tens and remainder, properly labeled. Try this with a few different initial numbers. m.You final program should look like this. The user enters a number between 10 and 99 (validated), then the program calls the function f3 that gives both the quotient and the remainder of a division by 10. The two values are printed out (not in the f3 function, but in the main program).