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

question about pointers.

Hello All,
I am learning C++ at the moment. Going through the book of SAM of
learning C++ in 21 days I have learned about pointers that it is good
custome to always initialise them and to use delete before you try to
give it a new address.
Can anyone explain to me why this code below which seems to voilate
this rule works ?

-------------------
int main()
20: {
21: CAT * Family[500];
22: int i;
23: CAT * pCat;
24: for (i = 0; i < 500; i++)
25: {
26: pCat = new CAT;
27: pCat->SetAge(2*i +1);
28: Family[i] = pCat;
29: }
30:
31: for (i = 0; i < 500; i++)
32: {
33: cout << "Cat #" << i+1 << ": ";
34: cout << Family[i]->GetAge() << endl;
35: }
36: return 0;
37: }
---------------
This code seems to work. But I thought it should be different according
to the customs of pointers. So I changed the code to;
----------------
int main()
20: {
21: CAT * Family[500];
22: int i;
23: CAT * pCat = 0;
24: for (i = 0; i < 500; i++)
25: {
26: pCat = new CAT;
27: pCat->SetAge(2*i +1);
28: Family[i] = pCat;
delete pCat;
pCat = 0;
29: }
30:
31: for (i = 0; i < 500; i++)
32: {
33: cout << "Cat #" << i+1 << ": ";
34: cout << Family[i]->GetAge() << endl;
35: }
36: return 0;
37: }
-----------------------
So I initialised pCat to the null pointer and added the lines between
line 28-29. And now the code does not work. The output on line 34 gives
only zeros. Can anyone explain me what I am doing wrong. To my opinion
I am doing everything correct and according to the rules. But What am I
doing wrong ??
Thank you in advance for answering the question.

Best Regards,
Robert

Jul 23 '05 #1
9 1501

<wo*********@yahoo.com> schrieb im Newsbeitrag
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello All,
I am learning C++ at the moment. Going through the book of SAM of
learning C++ in 21 days I have learned about pointers that it is
good
custome to always initialise them and to use delete before you try
to
give it a new address.
Can anyone explain to me why this code below which seems to voilate
this rule works ?

-------------------
int main()
20: {
21: CAT * Family[500];
22: int i;
23: CAT * pCat;
24: for (i = 0; i < 500; i++)
25: {
26: pCat = new CAT;
27: pCat->SetAge(2*i +1);
28: Family[i] = pCat;
29: }
30:
31: for (i = 0; i < 500; i++)
32: {
33: cout << "Cat #" << i+1 << ": ";
34: cout << Family[i]->GetAge() << endl;
35: }
36: return 0;
37: }
---------------
This code seems to work. But I thought it should be different
according
to the customs of pointers. So I changed the code to;
----------------
int main()
20: {
21: CAT * Family[500];
22: int i;
23: CAT * pCat = 0;
24: for (i = 0; i < 500; i++)
25: {
26: pCat = new CAT;
27: pCat->SetAge(2*i +1);
28: Family[i] = pCat;
delete pCat;
pCat = 0;


ouch!
pCat points to valid memory.
Family[i] points to exactly that same memory
Now you delete that memory pointed to by pCat
Guess where Family[i] is pointing to now!?
Jul 23 '05 #2
"wo*********@yahoo.com" wrote:

Hello All,
I am learning C++ at the moment. Going through the book of SAM of
learning C++ in 21 days I have learned about pointers that it is good
custome to always initialise them and to use delete before you try to
give it a new address.
Can anyone explain to me why this code below which seems to voilate
this rule works ?
[snip]
So I initialised pCat to the null pointer and added the lines between
line 28-29. And now the code does not work. The output on line 34 gives
only zeros. Can anyone explain me what I am doing wrong. To my opinion
I am doing everything correct and according to the rules. But What am I
doing wrong ??


What the book did wrong: It obviously explained pointers and how to
deal with them in a way you did not understand.
What you did wrong: You don't understand pointers or to be more exact:
danymic memory allocation by now.

Here is the deal:
A pointer is a place in memory, just like any other variable that holds
the memory address of some other items in memory. As such it has a name
just like any other variable.

So when you program does

CAT * Family[500];
CAT * pCat;

you create 2 of those variables. Here they are:

pCat Family
+----------+ +------------+
| | | |
+----------+ +------------+
| |
+------------+
| |
+------------+
| |
. .
. .
. .
| |
+------------+
| |
+------------+

Each of those rectangles contains a pointer. At the moment they
are pointing to nowhere in particular, but that will change in
a moment. When a pointer points to something, I will indicate
that fact by placing an arrow in it. The arrow starts at the
rectangle and ends at the thing 'pointed to'. Note: If I want
to indicate that a pointer points to newhere, I simply write
a 0 into the rectangle. Since none of the rectangles contain
a 0 right now, I can conclude that nothing can be said about the
state of the pointers right now.

You program contines with

pCat = new CAT;

in the loop. OK lets perform the operation at i == 0

new CAT That means that a CAT object is born somewhere in memory ...
pCat = new CAt ... and pCat gets a pointer to it

pCat Family
+----------+ +------------+
| o | | |
+----|-----+ +------------+
| | |
| +------------+
| | |
| +------------+
| | |
| . .
| . .
| . .
| | |
| +------------+
| | |
| +------------+
|
| +------------+
+----------------------------------------->| Age: |
+------------+

Next:
pCat->SetAge(2*i + 1);

pCat Look up the rectangle called pCat
pCat-> There must be an arrow originating from it
Follow that arrow and you will get to an
object of type CAT
pCat->SetAge From that object, call the member function setAge
pCat->SetAge(2*i+1) and pass it the value 1 (remember, we ar ein the first
loop iteration, i has a value of 0)

I guess that SetAge simply will set the Age field, thus

pCat Family
+----------+ +------------+
| o | | |
+----|-----+ +------------+
| | |
| +------------+
| | |
| +------------+
| | |
| . .
| . .
| . .
| | |
| +------------+
| | |
| +------------+
|
| +------------+
+----------------------------------------->| Age: 1 |
+------------+

Next:
Family[i] = pCat;

Ok. In the array Family, look up the rectangle which corresponds to
the 0-th entry. Make that entry point to the same object as pCat

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
+----------------------------------------->| Age: 1 |
+------------+

Loop finished, lets make another turn through the loop, for i == 1

pCat = new CAT;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
| | Age: 1 |
| +------------+
|
|
| +------------+
+-------------------------------------->| Age: |
+------------+

pCat->SetAge( 2*i + 1);

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
| | Age: 1 |
| +------------+
|
|
| +------------+
+-------------------------------------->| Age: 3 |
+------------+

Family[i] = pCat;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | o------------+ |
| +------------+ | |
| | | | |
| +------------+ | |
| | | | |
| . . | |
| . . | |
| . . | |
| | | | |
| +------------+ | |
| | | | |
| +------------+ | |
| | v
| | +------------+
| | | Age: 1 |
| | +------------+
| |
| v
| +------------+
+------------------------------------->| Age: 3 |
+------------+

I guess you can now see what is going on:
New CAT objects are allocated, a pointer to them is held in pCat.
The object gets assigned some value and finaly the pointer in the
Family array is made to point to that object. So in the end, the
graphics would look like this: The family rectangle has pointers
pointing all over the place to CAT object, each with an Age number
set.

Now the final loop in the original program simply walks through
that array,

for( i = 0; i < 500; i++ )

follows each pointer

Family[i]->

tells the object at the end of the arrow to give its age

Family[i]->GetAge()

and outputs the number returned by the object

cout << Family[i]->GetAge() << endl;

So far so good.
But then came you and modified the program. Lets see how this influences
the whole program:

Again 2 Pointers are created:

CAT * Family[500];
CAT * pCat;

pCat Family
+----------+ +------------+
| | | |
+----------+ +------------+
| |
+------------+
| |
+------------+
| |
. .
. .
. .
| |
+------------+
| |
+------------+

in the loop ( i == 0 )

pCat = new CAT;
pCat->SetAge( 2*i+1);
Family[i] = pCat;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
+----------------------------------------->| Age: 1 |
+------------+

Nothing new so far.
But now it comes:

delete pCat;

Well. delete destroyes the object pCat points to. It wipes it out of memory.

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
|
+----------------------------------------->
pCat = 0;

pCat Family
+----------+ +------------+
| 0 | | o----------------+
+----------+ +------------+ |
| | |
+------------+ |
| | |
+------------+ |
| | |
. . |
. . |
. . |
| | |
+------------+ |
| | |
+------------+ |
v

Next run through the loop ( i == 1 )

pCat = new CAT;
pCat->SetAge( 2*i+1);
Family[i] = pCat;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | o-----------+ |
| +------------+ | |
| | | | |
| +------------+ | |
| | | | |
| . . | |
| . . | |
| . . | |
| | | | |
| +------------+ | |
| | | | |
| +------------+ | |
| | v
| |
| |
| v
| +----------+
+---------------------------------->| Age: 3 |
+----------+

and again:

delete pCat;
pCat = 0;

pCat Family
+----------+ +------------+
| O | | o----------------+
+----------+ +------------+ |
| o-----------+ |
+------------+ | |
| | | |
+------------+ | |
| | | |
. . | |
. . | |
. . | |
| | | |
+------------+ | |
| | | |
+------------+ | |
| v
|
|
v
I think you can imagine, what this leads to in the end. Family
still holds a lot of pointers. But there are no objects at the
end of all those arrows. They have all been deleted.

Well. Above I said: it has been wiped out of memory. Technically
this is impossible. Memory is memory. There is still memory at
all the end points of all those arrows and it is impossible for
memory to not hold some value. But logically those objects are no
longer there. The content of that memory is random and depends on a
lot of things outside your control. This is why the loop in your final
program outputs 0. It could have operated otherwise also. You program
could have simply crashed, because in the loop you take the pointer,
the arrow, follow it and tell the object at the end of the arrow
to give its age. But there is no object there any more!
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #3
On 26 Jan 2005 05:26:32 -0800, wo*********@yahoo.com
<wo*********@yahoo.com> wrote:
Hello All,
I am learning C++ at the moment. Going through the book of SAM of
learning C++ in 21 days I have learned about pointers that it is good
custome to always initialise them and to use delete before you try to
give it a new address.
Can anyone explain to me why this code below which seems to voilate
this rule works ?


[...]

which only shows once more that these 21-day books are not sooo good (i
know three of them)...

i would make myself familiar with std::auto_ptr<> as fast as possible, and
buy a better book, e.g.

http://www.amazon.com/exec/obidos/tg...986470-2641501

or

http://www.amazon.com/exec/obidos/AS...986470-2641501

and so on...

--
have a nice day
ulrich
Jul 23 '05 #4
> which only shows once more that these 21-day books are not sooo good
(i know three of them)...


I did the C in 21 days in 5 days and it was good. Haven't had a look
at C++ in 21 days, though.
-Gernot
Jul 23 '05 #5
Dear Karl Heinz Buchegger,

Thank you for your explanation. But if I understood you properly then
why does not the following code does not compile ?

----------

int *p = new int[5];
int *p = new int[10];

-----------
But when I write the following code here below which seems to be the
same for me that I redeclare the pointer to point again to somewhere
else, the compiler does not complain. WHy?? Do I have memory leak in
any of these cases ?
---------------
for (int i = 1; i<10; i++)
{
int *p = new int[i];
}
---------------

Robert

Karl Heinz Buchegger wrote:
"wo*********@yahoo.com" wrote:

Hello All,
I am learning C++ at the moment. Going through the book of SAM of
learning C++ in 21 days I have learned about pointers that it is good custome to always initialise them and to use delete before you try to give it a new address.
Can anyone explain to me why this code below which seems to voilate
this rule works ?
[snip]
So I initialised pCat to the null pointer and added the lines between line 28-29. And now the code does not work. The output on line 34 gives only zeros. Can anyone explain me what I am doing wrong. To my opinion I am doing everything correct and according to the rules. But What am I doing wrong ??


What the book did wrong: It obviously explained pointers and how to
deal with them in a way you did not understand.
What you did wrong: You don't understand pointers or to be more

exact: danymic memory allocation by now.

Here is the deal:
A pointer is a place in memory, just like any other variable that holds the memory address of some other items in memory. As such it has a name just like any other variable.

So when you program does

CAT * Family[500];
CAT * pCat;

you create 2 of those variables. Here they are:

pCat Family
+----------+ +------------+
| | | |
+----------+ +------------+
| |
+------------+
| |
+------------+
| |
. .
. .
. .
| |
+------------+
| |
+------------+

Each of those rectangles contains a pointer. At the moment they
are pointing to nowhere in particular, but that will change in
a moment. When a pointer points to something, I will indicate
that fact by placing an arrow in it. The arrow starts at the
rectangle and ends at the thing 'pointed to'. Note: If I want
to indicate that a pointer points to newhere, I simply write
a 0 into the rectangle. Since none of the rectangles contain
a 0 right now, I can conclude that nothing can be said about the
state of the pointers right now.

You program contines with

pCat = new CAT;

in the loop. OK lets perform the operation at i == 0

new CAT That means that a CAT object is born somewhere in memory ... pCat = new CAt ... and pCat gets a pointer to it

pCat Family
+----------+ +------------+
| o | | |
+----|-----+ +------------+
| | |
| +------------+
| | |
| +------------+
| | |
| . .
| . .
| . .
| | |
| +------------+
| | |
| +------------+
|
| +------------+
+----------------------------------------->| Age: |
+------------+

Next:
pCat->SetAge(2*i + 1);

pCat Look up the rectangle called pCat
pCat-> There must be an arrow originating from it
Follow that arrow and you will get to an
object of type CAT
pCat->SetAge From that object, call the member function setAge pCat->SetAge(2*i+1) and pass it the value 1 (remember, we ar ein the first loop iteration, i has a value of 0)

I guess that SetAge simply will set the Age field, thus

pCat Family
+----------+ +------------+
| o | | |
+----|-----+ +------------+
| | |
| +------------+
| | |
| +------------+
| | |
| . .
| . .
| . .
| | |
| +------------+
| | |
| +------------+
|
| +------------+
+----------------------------------------->| Age: 1 |
+------------+

Next:
Family[i] = pCat;

Ok. In the array Family, look up the rectangle which corresponds to
the 0-th entry. Make that entry point to the same object as pCat

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
+----------------------------------------->| Age: 1 |
+------------+

Loop finished, lets make another turn through the loop, for i == 1

pCat = new CAT;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
| | Age: 1 |
| +------------+
|
|
| +------------+
+-------------------------------------->| Age: |
+------------+

pCat->SetAge( 2*i + 1);

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
| | Age: 1 |
| +------------+
|
|
| +------------+
+-------------------------------------->| Age: 3 |
+------------+

Family[i] = pCat;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | o------------+ |
| +------------+ | |
| | | | |
| +------------+ | |
| | | | |
| . . | |
| . . | |
| . . | |
| | | | |
| +------------+ | |
| | | | |
| +------------+ | |
| | v
| | +------------+
| | | Age: 1 |
| | +------------+
| |
| v
| +------------+
+------------------------------------->| Age: 3 |
+------------+

I guess you can now see what is going on:
New CAT objects are allocated, a pointer to them is held in pCat.
The object gets assigned some value and finaly the pointer in the
Family array is made to point to that object. So in the end, the
graphics would look like this: The family rectangle has pointers
pointing all over the place to CAT object, each with an Age number
set.

Now the final loop in the original program simply walks through
that array,

for( i = 0; i < 500; i++ )

follows each pointer

Family[i]->

tells the object at the end of the arrow to give its age

Family[i]->GetAge()

and outputs the number returned by the object

cout << Family[i]->GetAge() << endl;

So far so good.
But then came you and modified the program. Lets see how this influences the whole program:

Again 2 Pointers are created:

CAT * Family[500];
CAT * pCat;

pCat Family
+----------+ +------------+
| | | |
+----------+ +------------+
| |
+------------+
| |
+------------+
| |
. .
. .
. .
| |
+------------+
| |
+------------+

in the loop ( i == 0 )

pCat = new CAT;
pCat->SetAge( 2*i+1);
Family[i] = pCat;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
| +------------+
+----------------------------------------->| Age: 1 |
+------------+

Nothing new so far.
But now it comes:

delete pCat;

Well. delete destroyes the object pCat points to. It wipes it out of memory.
pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | | |
| +------------+ |
| | | |
| +------------+ |
| | | |
| . . |
| . . |
| . . |
| | | |
| +------------+ |
| | | |
| +------------+ |
| v
|
+----------------------------------------->
pCat = 0;

pCat Family
+----------+ +------------+
| 0 | | o----------------+
+----------+ +------------+ |
| | |
+------------+ |
| | |
+------------+ |
| | |
. . |
. . |
. . |
| | |
+------------+ |
| | |
+------------+ |
v

Next run through the loop ( i == 1 )

pCat = new CAT;
pCat->SetAge( 2*i+1);
Family[i] = pCat;

pCat Family
+----------+ +------------+
| o | | o----------------+
+----|-----+ +------------+ |
| | o-----------+ |
| +------------+ | |
| | | | |
| +------------+ | |
| | | | |
| . . | |
| . . | |
| . . | |
| | | | |
| +------------+ | |
| | | | |
| +------------+ | |
| | v
| |
| |
| v
| +----------+
+---------------------------------->| Age: 3 |
+----------+

and again:

delete pCat;
pCat = 0;

pCat Family
+----------+ +------------+
| O | | o----------------+
+----------+ +------------+ |
| o-----------+ |
+------------+ | |
| | | |
+------------+ | |
| | | |
. . | |
. . | |
. . | |
| | | |
+------------+ | |
| | | |
+------------+ | |
| v
|
|
v
I think you can imagine, what this leads to in the end. Family
still holds a lot of pointers. But there are no objects at the
end of all those arrows. They have all been deleted.

Well. Above I said: it has been wiped out of memory. Technically
this is impossible. Memory is memory. There is still memory at
all the end points of all those arrows and it is impossible for
memory to not hold some value. But logically those objects are no
longer there. The content of that memory is random and depends on a
lot of things outside your control. This is why the loop in your final program outputs 0. It could have operated otherwise also. You program
could have simply crashed, because in the loop you take the pointer,
the arrow, follow it and tell the object at the end of the arrow
to give its age. But there is no object there any more!
--
Karl Heinz Buchegger
kb******@gascad.at


Jul 23 '05 #6
"wo*********@yahoo.com" wrote:

Dear Karl Heinz Buchegger,

Thank you for your explanation. But if I understood you properly then
why does not the following code does not compile ?

----------

int *p = new int[5];
int *p = new int[10];

Simple. Because you try to define 2 variables with the very same
name. There really is no difference to

int i = 0;
int i = 5;

After all, a pointer variable is just that: a variable.
-----------
But when I write the following code here below which seems to be the
same for me that I redeclare the pointer to point again to somewhere
else, the compiler does not complain. WHy?? Do I have memory leak in
any of these cases ?
---------------
for (int i = 1; i<10; i++)
{
int *p = new int[i];
}
---------------


Because here the lifetime of the variable p is the block under the for
loop. So whenever the loop is restarted, all variables declared inside
the loop are destroyed and get created again in the next loop repetition.

Look up: lifetime of variables. Basically it says: Whenever a '}' is reached
all variables declared in the corresponding block get destroyed.

And yes, the above would be a memory leak.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #7
On Wed, 26 Jan 2005 16:43:34 +0100, Gernot Frisch <Me@Privacy.net> wrote:
which only shows once more that these 21-day books are not sooo good
(i know three of them)...


I did the C in 21 days in 5 days and it was good.


exactly. was good for your first 5 days of programming.

as long as one follows the book's examples, everything is fine. as soon as
you leave the tracks or want / need to know more, you're lost.

just imho, and formulated a bit exaggerated.

--
have a nice day
ulrich
Jul 23 '05 #8

"Karl Heinz Buchegger" <kb******@gascad.at> schrieb im Newsbeitrag
news:41***************@gascad.at...
"wo*********@yahoo.com" wrote:

Dear Karl Heinz Buchegger,

Thank you for your explanation. But if I understood you properly
then
why does not the following code does not compile ?

----------

int *p = new int[5];
int *p = new int[10];


This compiles:
int* p=new int[5];
p=new int[10];
Forget about ever getting a chance for delete-ing the int[5] from now
on - you have a memory leak.
However, this is OK:

int*p, *q;
p = new int[5]; q=p;
p = new int[10];

delete [] p; // [10]
delete [] q; // [5]

-Gernot
Jul 23 '05 #9
wo*********@yahoo.com wrote:
Hello All,
I am learning C++ at the moment. Going through the book of SAM of
learning C++ in 21 days I have learned about pointers that it is good
custome to always initialise them and to use delete before you try to
give it a new address.


Others have answered why it broke: what you have learned here is that
SAMs books are an ok introduction to the language, but you will not know
it until you have read some better books. C++ in 21 days will only give
you a rough understanding of what's going on. I don't think it has
anything blatantly wrong in it, though.

--
Will Twentyman
email: wtwentyman at copper dot net
Jul 23 '05 #10

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

Similar topics

16
by: cppaddict | last post by:
Hi, I am deleting some objects created by new in my class destructor, and it is causing my application to error at runtime. The code below compiles ok, and also runs fine if I remove the body...
11
by: DamonChong | last post by:
Hi, I am new to c++. I recently spend an enormous among of time troubleshooting a seeminly innocuous piece of code. Although I narrow down this piece of code as the culprit but I don't...
27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
20
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some...
9
by: Alfonso Morra | last post by:
Hi, I am having some probs with copying memory blocks around (part of a messaging library) and I would like some confirmation to make sure that I'm going about things the right way. I have...
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
21
by: Bo Yang | last post by:
As long as I write c++ code, I am worry about the pointer. The more the system is, the dangerous the pointer is I think. I must pass pointers erverywhere, and is there a way to ensure that every...
3
by: Filimon Roukoutakis | last post by:
Dear all, assuming that through a mechanism, for example reflexion, the Derived** is known explicitly. Would it be legal (and "moral") to do this conversion by a cast (probably reinterpret would...
21
by: Chad | last post by:
At the following url http://c-faq.com/lib/qsort2.html, they have the following Q: Now I'm trying to sort an array of structures with qsort. My comparison function takes pointers to structures,...
17
by: Ben Bacarisse | last post by:
candide <toto@free.frwrites: These two statements are very different. The first one is just wrong and I am pretty sure you did not mean to suggest that. There is no object in C that is the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.