?
Solved

function

Posted on 2003-03-18
10
Medium Priority
?
238 Views
Last Modified: 2010-04-17
void Transmit (char *pMessage);
...
...
...
return...

Q1) Return value of function of the above example is to variable *pMessage. Is it possible to make the return value to another variable (of other function)?

Q2) Can I call another function in the function shown above?
0
Comment
Question by:bbtss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 700 total points
ID: 8164347
>> Return value of function of the above example is to variable *pMessage.

The specified return-type is void. It can't return any value. However, the modifications made in the location pointed to by 'pMessage' will be permanent and reflected in the function which called this function.

>>  Is it possible to make the return value to another variable (of other function)?

You will have to change the return-type from 'void' to something else - whatever data-type you want to return. But you will not be able to access any local variable of another function.

>>  Is it possible to make the return value to another variable (of other function)?

You can call as many defined functions as you want from the above function.

Mayank.

0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 8164725
>> However, the modifications made in the location pointed to by 'pMessage' will be permanent
erh, I doubt this mayank, it'd have to be referenced
char*& pMessage
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8164765
>> it'd have to be referenced

Not at all! An array will always be passed by address. So if he passes an array to this function, then any modificatoins made in the array in this function will be permanent and reflected in the calling function.

Also, supposing that he simply passes an address as:

char ch = 'A' ;
Transmit ( &ch ) ;
printf ( "%c", ch ) ;

where Transmit () is:

void Transmit ( char * pMessage )
{
  * pMessage = 'B' ;

} // end of Transmit ()

The output will definitely be B, not A, because you have passed the address of 'ch', and so, in Transmit (), pMessage points to the same location in which the 'ch' of the calling function, and so when you write:

* pMessage = 'B' ;

You mean: store 'B' at the location pointed to by 'pMessage' and so, the change is reflected permanently.

Mayank.

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 4

Expert Comment

by:n_fortynine
ID: 8164818
My bad mayankeagle, i was thinking pMessage not *pMessage. =) i should just go to bed
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8164885
Oh that's all right, n_fortynine. And don't get ever write: char * & pMessage, as you'd written in your previous comment.

Cheers,

Mayank.
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 8164907
well i suppose if i want to make changes to pMessage itself i could still do char*& though, ;)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8164983
>> make changes to pMessage itself

You mean changes to the pointer in the calling function (which was passed)??

Actually, I asked you to avoid this notation because it might create lots of confusion if you pass an address (like &ch), instead of a pointer (like Transmit (p) ; where p is a pointer). I would prefer to use a pointer to a pointer, if I needed to do something of that sort.

Mayank.
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 8165339
it all depends on what i usually do. i actually mess around with pointers more than i do with address-passing so my brain always functions in a, say =), "pointer-oriented" way LOL... i think it's all up to the context which we are writing to decide how to write it. just curious, how do you use ** to, say increment the addr of an array? [aye i'm learning something here...]
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8165369
>> increment the addr of an array

You cannot increment the address of an array! You can have a pointer pointing to the base address of the array and increment that pointer.

If you have:

int ** p ;

And p is a pointer to a pointer which is holding the base address of an array:

int * q ;
int a[] = { 1, 2, 3, 4, 5 } ;

q = a ;
p = & q ;

Then, to increment q, you can write:

( * p ) ++ ; // or q ++ ;

Then, printf ( "%d", * q ) ; will print 2.

Mayank.
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 8165476
that's what i meant - the base addr (sorry for the confusion). i know how to do it indirectly via a second ptr. i just thought you were doing it directly when passing the object ptr to a function. anyway, it'll work fine.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question