473,320 Members | 1,948 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,320 software developers and data experts.

can functions return a struct?

I am just asking if i can return the values of a struct on a function??
example:
typedef struct sample{
int a;
char b, c;
}SAMPLE_STRUCT;

can it be like this?

//function prototype
SAMPLE_STRUCT copy_struct(void);

Is this correct???
Sep 1 '06 #1
3 60811
It is possible. In header file:

typedef struct sample
{
int a;
char b, c;
}
SAMPLE_STRUCT;
//////
SAMPLE_STRUCT GetSample();

************************************
In source file:

SAMPLE_STRUCT GetSample()
{
SAMPLE_STRUCT sample_struct;

sample_struct.a = 5;
sample_struct.b = 6;
sample_struct.c = 7;

return sample_struct;
}

Also GetSample may the member function of some class, but in this case the structure is must be visible for this class.
Sep 1 '06 #2
rgb
37
you can also pass your structure as a pointer parameter in your function to make changes in the variables inside the sturcture.
Sep 1 '06 #3
It is possible. In header file:

typedef struct sample
{
int a;
char b, c;
}
SAMPLE_STRUCT;
//////
SAMPLE_STRUCT GetSample();

************************************
In source file:

SAMPLE_STRUCT GetSample()
{
SAMPLE_STRUCT sample_struct;

sample_struct.a = 5;
sample_struct.b = 6;
sample_struct.c = 7;

return sample_struct;
}

Also GetSample may the member function of some class, but in this case the structure is must be visible for this class.


PLZ. this is must be visible in the same class, if I want see struct variables in the other class.


Thank you in advance.
May 3 '07 #4

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

Similar topics

6
by: lawrence | last post by:
If I want a function to return by reference, I do this? function & myCoolFunction() { $queryObject = new queryObject(); return $queryObject; } I get back a reference to the object...
3
by: Zork | last post by:
Hi, I am a little confused with const functions, for instance (here i am just overloading the unary+ operator) if i define: 1) Length Length :: operator+ ( void ) const {return * this;} ... I...
3
by: BJT | last post by:
Hello, How can I return a struct type e.g. System::Drawing::Point from a managed c++ class to a C# assembly? When I have the declaration of the managed C++ class's member function as...
127
by: sanjay.vasudevan | last post by:
Why are the following declarations invalid in C? int f(); int f(); It would be great if anyone could also explain the design decision for such a language restricton. Regards, Sanjay
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.