473,378 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

return value by reference from a sub-function

I have computed an array y[100] in a subfunction.

The value of y needs to be referenced in the main function.

Is it possible for me to pass the address of y[100] from the sub-function to the main function using the statement 'return(&y);' and reference y in main function using a pointer?

Is there any similar way to access the variables by reference in a sub-function?
May 29 '10 #1
2 1763
Banfa
9,065 Expert Mod 8TB
If you created y as a local variable of the sub-function then no because when the function exits the variable is deleted.

You could declare the array in main and pass a pointer to it into the sub-function then the sub-function will work on the array in main.
May 29 '10 #2
Hi Banfa,
Thanks a lot for your suggestion.
You have solved my problem.

Thank you and regards :-)
May 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eric Lilja | last post by:
Hello, consider this complete program: #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class Hanna {
7
by: Rudy | last post by:
Hello All! I have a value in a textbox(txbTableIDm.Text ) that I would like to use in a paremiter in a SP I wrote, and then have the select statement work off that parememter, retireive a...
8
by: solomon_13000 | last post by:
The code bellow functions well. However if I want to obtain a return value using the code bellow, how is it done? <% Sub RunQueryString (pSQL,parms) on error resume next Set conn =...
14
by: tshad | last post by:
Is there any difference between Return and Exit Sub? I have some code that uses both when I have an error in my Sub. Thanks, Tom
6
by: Bo Yang | last post by:
I know the below code is wrong: Object & test(){ return Object() ;} Object & v = test() ; the Object is just a temporary variable, so you the variable may be reference to nothing. And I...
5
by: johnny | last post by:
I have the following PHP code. I am using PHP 5.1.6. $req =& new HTTP_Request($this->accessUrl); I am getting the following errors: Strict Standards: Assigning the return value of new by...
4
by: Zytan | last post by:
It seems I cannot return a reference to a value type as the return value of a method. I will have to use an out parameter instead. Is there another way to do it? Zytan
4
by: Mick Walker | last post by:
Hi Everyone, I am stumped here. I have the following stored proceedure:P CREATE PROCEDURE . @SupplierSKU varchar(50), @RetVal int AS Select @Retval = count(*) from dbo.ImportLines Where =...
2
by: Mick Walker | last post by:
Public Sub CheckProduct(ByVal _ConnString As String, ByVal ProductList As List(Of Import_ImportLines.Lines)) Dim ReturnValue As Integer = 0 ' Our Return Value Dim conn As New SqlConnection Dim...
10
by: flopbucket | last post by:
Hi, Is this legal? std::string foo() { std::string xyz = "FOO"; return xyz; }
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.