Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basics -pointing to variables

Status
Not open for further replies.

sunaj

Technical User
Joined
Feb 13, 2001
Messages
1,474
Location
DK
Hi,

I'm trying to get this C code working that I got, but knowing little of C I'm failing misserably. A little help from you can hopefully get me on the right track.
This one is probably simple...

A procedure takes a number of parameters, some of them are the return values and they are declared as e.g. 'float *y'.
How do I declare & pass a variable to return from such a sub?
I've made an example that illustrates (this code generates an error in line '*y=(float) 2'. Remember that I can't change sub1):

-----------------------------------------------
#include <iostream.h>

void sub1(float *y) {
*y=(float) 2;
}

void main() {
float *x;
sub1(x);
cout << sub1;
}
----------------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
I found out myself - thx for your attention anyway... Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
float x;
sub1(&x);

dunno if this is what you did or not.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top