C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

to improve programming in pointers

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
sivashankar21@gmail.com
Guest





PostPosted: Sat Feb 25, 2006 5:06 am    Post subject: to improve programming in pointers Reply with quote



how i can improve my programming skill in pointer using c++
Back to top
benben
Guest





PostPosted: Sat Feb 25, 2006 6:06 am    Post subject: Re: to improve programming in pointers Reply with quote



by more reading and practices.

Ben
Back to top
Gianni Mariani
Guest





PostPosted: Sat Feb 25, 2006 7:06 am    Post subject: Re: to improve programming in pointers Reply with quote



sivashankar21 (AT) gmail (DOT) com wrote:
Quote:
how i can improve my programming skill in pointer using c++


Go find the answers to these questions.


struct A { int a; };

struct B : A { int b; };

A xa[ 10 ];
B xb[ 10 ];

A * pa = xb;
// Q1 - what is the value of pa pointing to ?

A * pBAD = pa + 1;
// Q2 - why is pBAD, bad ?

B * pb = xb;
// - same as Q1

A * paOK = pb + 1;
// Q3 - what does paOK point to ?


A (&( * pf )( int * ))[ 10 ];
// Q4 - what is pf ?

A * paX = & pb[1];

bool b( paX == paOK );
// Q5 - what is the value of b

A * paY = & pb[3];

int iNOTGOOD( paY - paX );
// Q6 - Why is iNOTGOOD not good ?

A * paM = new B;

int main()
{

delete paM; // line Z - NOT GOOD
// Q7 - why is line Z a bad thing ?

paM = 0;
// Q8 - what is paM now ?

delete paM;
// Q9 - what does delete paM do ?

bool x( & (* xb).b == & xb->b );
// Q10 - What is the value of x ?
}

B * F()
{
B x[2];

return x; // doh !
// Q11 - Why is the line marked "doh" broken ?
}
Back to top
loufoque
Guest





PostPosted: Sat Feb 25, 2006 3:06 pm    Post subject: Re: to improve programming in pointers Reply with quote

sivashankar21 (AT) gmail (DOT) com a écrit :
Quote:
how i can improve my programming skill in pointer using c++


You shouldn't even use pointers.
Avoid them as much as possible and only use them when it's needed.
Back to top
Default User
Guest





PostPosted: Sat Feb 25, 2006 5:06 pm    Post subject: Re: to improve programming in pointers Reply with quote

loufoque wrote:

Quote:
sivashankar21 (AT) gmail (DOT) com a écrit :
how i can improve my programming skill in pointer using c++


You shouldn't even use pointers.
Avoid them as much as possible and only use them when it's needed.

At which point he won't know how to use them.



Brian

--
If televison's a babysitter, the Internet is a drunk librarian who
won't shut up.
-- Dorothy Gambrell (http://catandgirl.com)
Back to top
Gianni Mariani
Guest





PostPosted: Sat Feb 25, 2006 11:06 pm    Post subject: Re: to improve programming in pointers Reply with quote

Ian Collins wrote:
....
Quote:

Are there any (real world) instances where pointers can't be avoided?

Let's see:

a) the "this" keyword.

b) When you may or may not want to pass an interface ... e.g.

void DoThing( const A & a, ErrorReporter * e = 0 );

c) Intrusive reference counted objects.

d) When objects point to one another i.e. a<->b

+ many more
Back to top
Ian Collins
Guest





PostPosted: Sat Feb 25, 2006 11:06 pm    Post subject: Re: to improve programming in pointers Reply with quote

Default User wrote:
Quote:
loufoque wrote:


sivashankar21 (AT) gmail (DOT) com a écrit :

how i can improve my programming skill in pointer using c++


You shouldn't even use pointers.
Avoid them as much as possible and only use them when it's needed.


At which point he won't know how to use them.

But he may have developed sufficient skill in in avoiding them so he

doesn't have to!

Are there any (real world) instances where pointers can't be avoided?

--
Ian Collins.
Back to top
Gianni Mariani
Guest





PostPosted: Sun Feb 26, 2006 1:06 am    Post subject: Re: to improve programming in pointers Reply with quote

Ian Collins wrote:
....
Quote:

With the exception of a, all these can be replace by some form of smart
pointer object.

You still need to understand pointers even if you're managing them using
smart pointers.
Back to top
Ian Collins
Guest





PostPosted: Sun Feb 26, 2006 1:06 am    Post subject: Re: to improve programming in pointers Reply with quote

Gianni Mariani wrote:
Quote:
Ian Collins wrote:
....


Are there any (real world) instances where pointers can't be avoided?


Let's see:

a) the "this" keyword.

b) When you may or may not want to pass an interface ... e.g.

void DoThing( const A & a, ErrorReporter * e = 0 );

c) Intrusive reference counted objects.

d) When objects point to one another i.e. a<->b

+ many more

With the exception of a, all these can be replace by some form of smart
pointer object.

--
Ian Collins.
Back to top
Ian Collins
Guest





PostPosted: Sun Feb 26, 2006 7:06 am    Post subject: Re: to improve programming in pointers Reply with quote

Gianni Mariani wrote:
Quote:
Ian Collins wrote:
....


With the exception of a, all these can be replace by some form of
smart pointer object.


You still need to understand pointers even if you're managing them using
smart pointers.

True enough, but I was trying to think of an example where raw pointers

can't be replaced with smart pointers.

--
Ian Collins.
Back to top
benben
Guest





PostPosted: Sun Feb 26, 2006 12:06 pm    Post subject: Re: to improve programming in pointers Reply with quote

Quote:
True enough, but I was trying to think of an example where raw pointers
can't be replaced with smart pointers.


When you are writing your own smart pointers? Perhaps?

Ben
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.