Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

arrays and pointers question


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)

Given:
        struct StructB b;
you may access the element with index `i' with:
        b.ptr_[i]
--
"The fact that there is a holy war doesn't mean that one of the sides
 doesn't suck - usually both do..."
--Alexander Viro

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

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

quasimodo wrote:
>> Given:
>>         struct StructB b;
>> you may access the element with index `i' with:
>>         b.ptr_[i]

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

struct StructA a[2];

b.ptr_ = a;

--
Tor <torust [at] online [dot] no>

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc