Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what is the difference between char*& and char*

Reply
Thread Tools

what is the difference between char*& and char*

 
 
gevadas@gmail.com
Guest
Posts: n/a
 
      07-29-2006
sample program

#include <iostream>
#include <vector>
using namespace std;


int find(char*& value,char** arr,int size)
{
for(int i = 0;i < size;i++)
{
if(strcmp(arr[i],value) == 0)
return i;
}
}




int main()
{
char* word = "two";
char* arr[4] = {"one","two","three","four"};
int res = find(word,arr,4);
cout << res;
}


the above program works fine even if the find was defined as follows


int find(char* value,char** arr,int size)
{
for(int i = 0;i < size;i++)
{
if(strcmp(arr[i],value) == 0)
return i;
}
}

It will be of great help if someone can tell me the difference b/w
char* and char&*

Thanks

Geaves

 
Reply With Quote
 
 
 
 
Daniel T.
Guest
Posts: n/a
 
      07-29-2006
In article <(E-Mail Removed). com>,
"(E-Mail Removed)" <(E-Mail Removed)> wrote:

> It will be of great help if someone can tell me the difference b/w
> char* and char&*


void exampleA( const char* value )
{
value = "exampleA";
}

void exampleB( const char*& value )
{
value = "exampleB";
}

int main()
{
char* value = "main";
exampleA( value );
assert( strcmp( value, "main" ) == 0 );

exampleB( value );
assert( strcmp( value, "exampleB" ) == 0 );
}

Hope that helps.
 
Reply With Quote
 
 
 
 
Frederick Gotham
Guest
Posts: n/a
 
      07-29-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) posted:

> It will be of great help if someone can tell me the difference b/w
> char* and char&*



char*: A pointer to a char.

char*&: A reference to a pointer to a character.

int main()
{
char c = 'a'; /* This is a char */

char *p = &c; /* This is a pointer to a char */

char *&rp = p; /* This is a reference to a pointer to a char */


/* Now "rp" and "p" are the exact same object.
You can confirm this with simple tests: */

if(p == rp) DoSomething();

if(&p == &rp) DoSomething();
}

--

Frederick Gotham
 
Reply With Quote
 
gevadas@gmail.com
Guest
Posts: n/a
 
      07-31-2006
Thank You

Geaves
Frederick Gotham wrote:
> (E-Mail Removed) posted:
>
> > It will be of great help if someone can tell me the difference b/w
> > char* and char&*

>
>
> char*: A pointer to a char.
>
> char*&: A reference to a pointer to a character.
>
> int main()
> {
> char c = 'a'; /* This is a char */
>
> char *p = &c; /* This is a pointer to a char */
>
> char *&rp = p; /* This is a reference to a pointer to a char */
>
>
> /* Now "rp" and "p" are the exact same object.
> You can confirm this with simple tests: */
>
> if(p == rp) DoSomething();
>
> if(&p == &rp) DoSomething();
> }
>
> --
>
> Frederick Gotham


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 04-15-2011 04:00 AM
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 01-06-2011 05:00 PM
difference between between these "char"s arnuld C++ 33 03-05-2007 03:11 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments