Click here to Skip to main content
15,888,401 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: activex dll problem Pin
maxMESA19-Apr-09 7:14
maxMESA19-Apr-09 7:14 
Questionpoint reference VS value Pin
sharion18-Apr-09 21:18
sharion18-Apr-09 21:18 
AnswerRe: point reference VS value Pin
Stuart Dootson18-Apr-09 22:53
professionalStuart Dootson18-Apr-09 22:53 
GeneralRe: point reference VS value Pin
sharion19-Apr-09 1:35
sharion19-Apr-09 1:35 
GeneralRe: point reference VS value Pin
Luc Pattyn19-Apr-09 1:49
sitebuilderLuc Pattyn19-Apr-09 1:49 
GeneralRe: point reference VS value Pin
Stuart Dootson19-Apr-09 1:52
professionalStuart Dootson19-Apr-09 1:52 
GeneralRe: point reference VS value Pin
sharion19-Apr-09 3:21
sharion19-Apr-09 3:21 
GeneralRe: point reference VS value Pin
Stuart Dootson19-Apr-09 3:52
professionalStuart Dootson19-Apr-09 3:52 
sharion wrote:
Based on experience previous, I take it for granted that whatever you have done to p have the same effect to str. That is passing by reference what I previously thought


What you are actually doing in your code is passing the pointer str by value. At the same time, you are passing by reference is what str points to.

C always passes parameters by value. So, when you want to pass a parameter by reference, you need to get a pointer to the value and pass the pointer by value to the function. So, this function takes x by value and returns a value calculated from x.

int Double(int x)
{
   return x + x;
}


while this function does the same, but passing x by pointer. To show that the actual value you pass to the function is not the one you're passing by pointer, I've changed the parameter to pX, meaning 'pointer to X'.

int Double(int *pX)
{
   return (*pX) + (*pX);
}


Now, let's move on to some string functions. Let's calculate the length of a C string:

int StringLength(char* s)
{
   int length = 0;
   while (*(s + length) != 0)
      ++length;
}


Now, what is s? It's a string, right? But in C, a string is just a pointer to the first character of the string! So, we're passing a pointer to the sequence of characters that make up the string. And we're passing that pointer by value. What we're passing by pointer is the characters that make up the string.

This page[^] and the ones it links to (especially the one about modifying function arguments[^] might help explain it better than I can - I've never been a good teacher Smile | :)

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: point reference VS value Pin
Luc Pattyn19-Apr-09 4:05
sitebuilderLuc Pattyn19-Apr-09 4:05 
GeneralRe: point reference VS value Pin
Stuart Dootson19-Apr-09 4:24
professionalStuart Dootson19-Apr-09 4:24 
GeneralRe: point reference VS value Pin
Luc Pattyn19-Apr-09 4:37
sitebuilderLuc Pattyn19-Apr-09 4:37 
GeneralRe: point reference VS value Pin
Stuart Dootson19-Apr-09 4:56
professionalStuart Dootson19-Apr-09 4:56 
GeneralRe: point reference VS value Pin
Luc Pattyn19-Apr-09 5:00
sitebuilderLuc Pattyn19-Apr-09 5:00 
GeneralRe: point reference VS value Pin
Stuart Dootson19-Apr-09 5:04
professionalStuart Dootson19-Apr-09 5:04 
GeneralRe: point reference VS value Pin
sharion19-Apr-09 5:25
sharion19-Apr-09 5:25 
GeneralRe: point reference VS value Pin
Stuart Dootson19-Apr-09 7:15
professionalStuart Dootson19-Apr-09 7:15 
GeneralRe: point reference VS value Pin
sharion20-Apr-09 18:30
sharion20-Apr-09 18:30 
GeneralRe: point reference VS value Pin
Stuart Dootson20-Apr-09 19:40
professionalStuart Dootson20-Apr-09 19:40 
GeneralRe: point reference VS value Pin
sharion21-Apr-09 18:05
sharion21-Apr-09 18:05 
GeneralRe: point reference VS value Pin
Stuart Dootson21-Apr-09 21:39
professionalStuart Dootson21-Apr-09 21:39 
GeneralRe: point reference VS value Pin
sharion22-Apr-09 16:00
sharion22-Apr-09 16:00 
QuestionProblem with headers in VS 2008 [modified] Pin
mass8518-Apr-09 10:07
mass8518-Apr-09 10:07 
AnswerRe: Problem with headers in VS 2008 Pin
Luc Pattyn18-Apr-09 10:33
sitebuilderLuc Pattyn18-Apr-09 10:33 
GeneralRe: Problem with headers in VS 2008 Pin
mass8518-Apr-09 11:08
mass8518-Apr-09 11:08 
GeneralRe: Problem with headers in VS 2008 Pin
Stuart Dootson18-Apr-09 11:36
professionalStuart Dootson18-Apr-09 11:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.