473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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","t hree","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 20824
In article <11************ **********@i3g2 000cwc.googlegr oups.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.c om 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.c om 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
2741
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 ========================================== We can see that the same assembly code is generated for * foo2 (char& )
8
2240
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
3
14350
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
3501
by: pembed2003 | last post by:
Hi coders, I have the following: void f1(char* &s){ *s = 'a'; } void f2(char* s){ *s = 'b'; }
2
1678
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
2225
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------ #include <iostream> void g(char&){}; void h(const char&) {}; int main() { char c;
0
1350
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), Salary number(10,2),......) Now, there is an index on the Empno field. Now, inside a stored procedure, I am executing a statement select Name=Ename from Emp where Empno=@eno This @eno is varchar(25). So, SQL Server would do the implicit...
5
4739
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 size? like
0
8397
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.