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

What is **

Hi all,
i have a question.
What does those ** mean???
For example:

void function(Something **pSomething);

I hope someone can help me about it.

Thanks,
FroxX
Jul 22 '05 #1
3 1730
Hi,

"FroxX" <fl****@aol.com> wrote in message
news:20***************************@mb-m25.aol.com...
Hi all,
i have a question.
What does those ** mean???
For example:

void function(Something **pSomething);
It is a pointer to , a pointer to something.

This is usually done when you want to assign something to a pointer for
instance

#include <stdlib.h>
#include <memory.h>
void MyAlloc( void **ptr )
{
*ptr = malloc( 1000 );
}
int main()
{
void *Ptr=0;
MyAlloc( &Ptr );

// do something not so useful
memset( Ptr, 0, 1000 );

free( Ptr);

return 0;
}


I hope someone can help me about it.

Thanks,
FroxX

Jul 22 '05 #2
FroxX wrote:
Hi all,
i have a question.
What does those ** mean???
For example:

void function(Something **pSomething);

I hope someone can help me about it.

Thanks,
FroxX

A common example where this is used is the main function

#include <iostream>

int main(int argc, char** argv){
//[...]
}

In this case char** argv can be seen as an object containing many strings.

In C every array can by described as a pointer:
char array[] = "hello world";
is the same as
char* p_array = array;

The name of the array is the same as a pointer to the first element of the array.

As you probably know, a string is an array of chars in C.

If you want to pass many strings (which means many arrays of chars) as an
argument to a function for example (as it also happens with the main function),
you can store the pointers to each string in another array.

You will then have an array of pointers. (Again: Each of these pointers point to
an array, representing a string )
This array can be seen like this;

char* my-strings[] = { "hello world", "bye world" };

This pointer is the same as the array above

char** p_my-strings = my-strings;

because char** p_my-string is a pointer to the first element of char*
my-string[], which is a represenation of an array, as I wrote above. In this
case it represents an array of pointers to arrays.

Though this seems a bit confusing, it isn't that hard to understand.

Don't imagine an array as many elements in a row, but as an object. If you use
pointers to the first element of an array as representation of the array, you in
fact have one object only - the pointer. The only case, you should imagine an
array as a list of elements, is when you access the elements in the array.

Again, if you have an array of arrays, you have a pointer, to many pointers,
which is why it's written as char**

The version char** is needed, if you dynamically allocate memory with malloc(),
since malloc always returns pointers to the memory it has reserved. The returned
pointer is the only way to access the reserved memory. This programming
technique is important if you want to programm in a secure and resource friendly
way.

pointers to pointers are not limited to chars. This can be done with any kind of
datatype, including structs.

a pointer to a pointer is not necessarily an array of arrays, but this is what
it's used for in 90% of all cases. I actually don't know a case where else you
need pointers to pointers.

If you are programming a table (image you were the programmer of EXCEL). Then
each field of the table might be a pointer to a struct, which represents the Field.
The table then consists of pointers to pointers to pointers, why you'd say
Field*** table;
greets Boris

Jul 22 '05 #3
hi Boris,

wie ich sehe bist du aus deutschland.
Danke für die ausführliche Erklärung!!!

//In English:
I see you're from Germany.
Thanks for the description!!!

CU, FroxX
FroxX, Germany, NRW, C++ Beginner, Froxxinating.de (excuse it, but i didnt work
on it for long) :o)
Jul 22 '05 #4

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

Similar topics

2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
8
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.