Solved

Something about pointers

Posted on 2000-04-13
7
185 Views
Last Modified: 2010-04-15
Could anybody help on the ** pointers. I have something like this:
typedef struct MyStructure{
XXX **BBB;
YYY **CCC;
}MyStructure;
In fact, If anybody could explain to me how this struct works,it be'll great.
Thanks.
0
Comment
Question by:asma
7 Comments
 
LVL 1

Accepted Solution

by:
MT_MU earned 50 total points
ID: 2714505
For the sake of illustration - assume XXX is actually char.

If we were to assume that that BBB is appropriately initialized.  *BBB would point to the addess of a string.

**BBB would point to the first character of the string pointed to by *BBB.

And for example....

char *Str1 = "1String";
char *Str2 = "2String";
char *Str3 = "3String";

MyStructure xyz;

xyz.BBB = (char **)malloc(sizeof(char *) * 3);
      
// Fill in our array

xyz.BBB[0] = Str1;      // This is the equivalant of *xyz.BBB = Str1;
xyz.BBB[1] = Str2;
xyz.BBB[2] = Str3;

// Loop through the strings...

char **strptr = xyz.BBB;

for (int i = 0; i < 3; i++)
{
  char* onestring = *strptr++;
}


free(xyz.BBB);
0
 
LVL 1

Expert Comment

by:mournblade
ID: 2714562
a pointer is a variables that contains an address. at that address is a value of the type XXX in your case.

now, if you have a double pointer, it means that the variable points to a place in memory where a pointer to XXX (or YYY) resides.

so you have

BBB of type XXX** points to -> a type XXX* that points to -> a value of type XXX

hope it's clear enough
0
 

Author Comment

by:asma
ID: 2714564
MT_MU,
I'm new to pointers & structures. In fact, my C knowledge are basic ones.If it get complicated, i'll be lost. Is there a good C bible out there that teaches you all these jargon?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Expert Comment

by:MT_MU
ID: 2714681
I kind of hate to admit this - but it's been so long since I started programming that I've forgotten what books seemed to help.  

I'll take a look and see if I still have some.

0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2714736
Asma,write your EMail and i 'll send you pointer tutorial.
Alex
0
 

Author Comment

by:asma
ID: 2714789
My email is asmawati@yahoo.com
0
 
LVL 8

Expert Comment

by:stochastic
ID: 2714836
asma,

You could try this book:
This is a wonderful book, especially if you want to do self-study.


The C Programming Language: ANSI C Version
Brian W. Kernighan  Dennis M. Ritchie

Paperback, 2nd ed., 272pp.
ISBN: 0131103628
Publisher: Prentice Hall
Pub. Date: May  1988
Price is about $40 to $60, depending on the binding and edition.

- stochastic

 
0

Featured Post

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now