arrays and pointers question

B

Bart Simpson

I have structs that looks like this:

struct StructA
{
//members ..
};


struct StructB
{
//members ..
struct StructA * ptr_
};


ptr_ is actually a ptr to an array of StuctA types. My question is, how
may I index into the array (pointed to by ptr_) given an index - (I
intentionally ignored array bounds checking to keep the question simple)
 
B

Ben Pfaff

Bart Simpson said:
I have structs that looks like this:

struct StructA
{
//members ..
};


struct StructB
{
//members ..
struct StructA * ptr_
};


ptr_ is actually a ptr to an array of StuctA types. My question is,
how may I index into the array (pointed to by ptr_) given an index -

Given:
struct StructB b;
you may access the element with index `i' with:
b.ptr_
 
Q

quasimodo

Given:
struct StructB b;
you may access the element with index `i' with:
b.ptr_



But you have to allocate the memory because * ptr_ is pointed random
memory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top