Thread View: csu.cs.200
3 messages
3 total messages
Started by x1e1r1
Thu, 08 Oct 1998 00:00
Test questions
Author: x1e1r1
Date: Thu, 08 Oct 1998 00:00
Date: Thu, 08 Oct 1998 00:00
3 lines
594 bytes
594 bytes
I must have missed something. What exactly do the extra *'s in front of a pointer mean? There were a few test questions about memory addresses that had these( int ***Q for example). Anyone?
Re: Test questions
Author: ken shrum
Date: Fri, 09 Oct 1998 00:00
Date: Fri, 09 Oct 1998 00:00
41 lines
1599 bytes
1599 bytes
x1e1r1@concentric.net wrote:
: I must have missed something. What exactly do the extra *'s in front of a
: pointer mean? There were a few test questions about memory addresses that
: had these( int ***Q for example). Anyone?
Something that looks like T* is "pointer to T", for any T. Hence, an
int*** is a pointer to pointer to pointer to int.
A C-ism carried over into C++ is that you often can't tell, when given
a T*, whether this is an array of T or a single T passed by address:
void print_ints(int n, int* arr) {
// int arr[n]
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
}
void get_length(char* str, int* len) {
// return len of str in len
*len = 0;
if (str != 0)
while (*str) {
str++;
(*len)++;
}
}
In print_ints, the int* is an array. In get_length, the int* is an
"output" parameter.
It's common to see, for example, an int**. This is often an array of
ints passed by address:
void get_array(int len, int** arr) {
*arr = new int[len];
}
More than two '*'s is pretty infrequent.
Ken Shrum
Re: multiple *'s
Author: cassic
Date: Fri, 09 Oct 1998 00:00
Date: Fri, 09 Oct 1998 00:00
23 lines
1548 bytes
1548 bytes
In article <6vk3sl$mie@journal.concentric.net>, <x1e1r1@concentric.net> wrote: > I must have missed something. What exactly do the extra *'s in front of a > pointer mean? There were a few test questions about memory addresses that > had these( int ***Q for example). Anyone? > Each * represents a pointer to something. So int ** means a pointer to a pointer to an int. Remember a pointer is actually an address in memory of some variable. So a pointer to a pointer is the address of a pointer variable, which contains an address to another variable. You can thus have pointers to pointers to pointers ... and so on. A very common use of pointers to pointers is in the passing of command line arguments to a main function in C/C++ (I won't go into it here). Chris -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads