Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C/C++ question: How to pass a variable by reference?

Status
Not open for further replies.

saturn

Member level 1
Joined
Jul 3, 2004
Messages
32
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Location
Solar System
Activity points
267
Hi,
1 year+ of assembly programming really spoil my C skill. I think there is a way to do this but forget how it can be done.

If I create a variable "char buf[80];", how could I pass it to a function so that inside the function, buf can be written directly.

Thanks & regards.
 

Geez ... you really need a C reference book.

void func1(char* buffer) {
...
*buffer = ...;
buffer++;
...
}

void main() {
char buf[80];
...
func1(buf);
...
}
 

By reference is actually c++, checkmate has given an example of the c method.
you could also do by reference, eg.

void cfunc(char* pszText)
{
// using c pointer
strcpy( pszText, "hello" );
}

void cpfunc(char& pszText)
{
// using c++ reference
strcpy( &pszText, "hello" );
}

void main(void)
{
char szText[80];
cfunc( szText );
cpfunc( *szText );
}

Both above will give the same results
Regards
NTFreak
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top