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

what is the difference between char*& and char*

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

Jul 29 '06 #1
3 20753
In article <11**********************@i3g2000cwc.googlegroups. com>,
"ge*****@gmail.com" <ge*****@gmail.comwrote:
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.
Jul 29 '06 #2
ge*****@gmail.com 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
Jul 29 '06 #3
Thank You

Geaves
Frederick Gotham wrote:
ge*****@gmail.com 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
Jul 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alex Vinokur | last post by:
========================================== Windows 2000 Professional CYGWIN_NT-5.0 1.5.4(0.94/3/2) GNU g++ version 3.2 20020927 (prerelease) GNU objdump 2.14.90 20030901...
8
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
3
by: Marcin Kalicinski | last post by:
void f(const char *&text); Is this a const reference to char * or a reference to const char *? And how to write both of them? thank you, Marcin
11
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
2
by: Zorro | last post by:
In header file istream there is an overload for every built-in type, except char. Is there a reason for this? GCC 3.3.4. is the compiler. Thanks.
5
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------ #include <iostream> void g(char&){}; void h(const char&) {}; int main() { char c;
0
by: Medhatithi | last post by:
I have a table whose indexed column is a char(16) field. I am giving the schema. CREATE TABLE Emp(Empno char(16), Ename varchar(25), ...
5
by: Samant.Trupti | last post by:
Hi, There is one thing I am cofused about.... If I have a declareation say char str; Now if I want to change it to wchar so do I have to change it like .... wchar_t str; or double the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.