473,500 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question on complicated pointer/reference declarations

Natasha26
12 New Member
I came across some strange declarations and am trying to get the hang of it. Any comments on how to read and use such decl. will be most welcomed.

1) Not sure if i understand this one. It could be that function f can be used to increment the address of a pointer. So to use f(...) give it an argument of type: int*

Expand|Select|Wrap|Line Numbers
  1.  void f(int*& i) { i++; } 
2) I got this one from pg35 of "C++ in a nutshell," i've put arrows to indicate where i got confused:
Expand|Select|Wrap|Line Numbers
  1. int x;           //some int
  2. int& r = &x;  //ref to int
  3. int* p = &x;  //pointer to int
  4. int*&* rp = &r;  //error: no pointer to ref  <---? 
  5. int*&* pr = p;   //ok: ref to pointer  <--- ?
  6.  
How do i read those in plain english and if i had a function f(int*&* p), or something more complicated, how do i know what type of argument it needs? thanks.
Mar 29 '08 #1
1 1282
weaknessforcats
9,208 Recognized Expert Moderator Expert
It's quite simple: A reference is an alias for another variable. That is, it is a second name for the variable.

You must bind the variable's name to the reference when the reference is created:
Expand|Select|Wrap|Line Numbers
  1. int a;
  2. int& b;              //ERROR reference variable not identified
  3. int& c = &a;      //ERROR a reference is not a pointer.
  4. int& c = a;        //OK. c and a are the same variable.
  5.  
  6.  
  7. int* d = & a;     //OK. d contains the address of a
  8.  
  9. int*& e = d;      //OK. e and d are the same variable.
  10.  
You see variable like e as function arguments. The argument becomes another name for the pointer in the calling function.

You could use:
Expand|Select|Wrap|Line Numbers
  1. int** f  = &d;
  2.  
Here you say that f contains the address of a pointer.

In a function argument, a variable like f is used to change the value inside d. You can use e the same way except you don't need to dereference e like you do f.
Mar 30 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2543
by: kazack | last post by:
I am under the the impression that a variable is what is stored in a memory address and a pointer is the memory address of the variable? I was looking to use a function that does not return a...
41
8268
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by...
7
1401
by: rs | last post by:
Just out of idle curiosity: 1)Regarding pointers; I don't have the standard/grammar with me, but T* for type T mean pointer-to-T. Does that mean that with a declaration of type T** is actually...
42
5565
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
41
9983
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
20
2067
by: ma0001yu | last post by:
Hi, all. I feel confuse about below struct definition: typedef struct TAG { comments.... }; What my confusion is: is typedef extra??why we not just use
14
7155
by: Vols | last post by:
If the people ask what is the different between pointer and reference, what is the brief and good answer? I say " pointer could point to NULL, but there is no null reference", What is your...
10
1875
by: mdh | last post by:
Sorry in advance if this is really dumb, but I am trying to get my head around exactly what the declarator is. In the FAQ, 1.21, part of it says "C declarations ....come in 2 parts, a base type and...
16
2740
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the...
0
7136
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,...
0
7182
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
7232
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...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
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
4611
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...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
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...

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.