473,657 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointer to an array of pointers

Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?

Regards
Dec 3 '07 #1
5 16693
On Dec 3, 7:13 pm, ramu <ramu....@gmail .comwrote:
Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?

Regards
*p or p[0].

A pointer to an array of N pointers is char *(*)[N].

Example:

char *(*foo)[N] = NULL;
Dec 3 '07 #2

"ramu" <ra******@gmail .comwrote in message
news:f0******** *************** ***********@s8g 2000prg.googleg roups.com...
Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?
/* set up a pointer to a list of pointers, here strings for readability */
char **strings;
int i;

strings = malloc(12 * sizeof(char *));
for(i=0;i<12;i+ +)
{
strings[i] = malloc(32);
sprintf(strings[i], "string %d", i+1);
}

/* dereference to get a string, or char * */
printf("%s\n", strings[3]);
/* dereference to get a character, should be the letter g */
printf("%c\n", strings[3][5]);

As you can see, when you say "dereferenc e the pointer" you can mean either
get what it points to immediately, which is another pointer, or what it
points to ultimately, which in this case is a char.

Also we can use this syntax

/* treat as pointer to single element */
printf("%s\n", *strings);

/* get first element of first element */
printf("%c\n", **strings);

This isn't so useful as the first. Usually when you want a pointer it is
because you have an array of things to point to, pointers to single items
are less common. However you'll need to know both syntaxes.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Dec 3 '07 #3
On Dec 3, 11:20 pm, "Malcolm McLean" <regniz...@btin ternet.comwrote :
"ramu" <ramu....@gmail .comwrote in message

news:f0******** *************** ***********@s8g 2000prg.googleg roups.com...Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?

/* set up a pointer to a list of pointers, here strings for readability */
char **strings;
int i;

strings = malloc(12 * sizeof(char *));
for(i=0;i<12;i+ +)
{
strings[i] = malloc(32);
sprintf(strings[i], "string %d", i+1);

}

/* dereference to get a string, or char * */
printf("%s\n", strings[3]);
/* dereference to get a character, should be the letter g */
printf("%c\n", strings[3][5]);

As you can see, when you say "dereferenc e the pointer" you can mean either
get what it points to immediately, which is another pointer, or what it
points to ultimately, which in this case is a char.
When you dereference a pointer you mean access what it points to.
In strings[3][5] you're dereferencing two pointers. strings and
strings[3].
Also we can use this syntax

/* treat as pointer to single element */
printf("%s\n", *strings);
*strings is equal to strings[0] and it has nothing to do with 'single
element'.
A pointer is of scalar type.

Really, i don't undestand your post, OP asked for a pointer to array
of pointers and you answered with a char **?
Dec 3 '07 #4
vi******@gmail. com wrote:
>
.... snip ...
>
Really, i don't undestand your post, OP asked for a pointer to
array of pointers and you answered with a char **?
A char** is a pointer to a pointer to char, which is what a
function will receive as a parameter to describe an array of
pointers to char. Remember that under most conditions an array is
described by a pointer to its zeroth element.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 4 '07 #5
On Mon, 3 Dec 2007 09:13:14 -0800 (PST), ramu <ra******@gmail .com>
wrote:
>Hi,
Could anyone please tell me how to dereference a pointer to an
array of pointers?
In strict terminology, a pointer to an array of pointers is
TYPE *arr[N];
TYPE *(*ptr)[N];
ptr = &arr;
ptr is a pointer to an array of N pointer to TYPE and points to one
such array.

In this case, ptr[0] is the array itself and ptr[0][i] is the i-th
pointer in the array.

Frequent, as in 99+%, newcomers to the language use the term to mean
TYPE *arr[N]
TYPE **ptr;
ptr =arr; /* or the equivalent ptr = &arr[0]; */
ptr is a pointer to pointer to TYPE and points to the first pointer in
the array of such pointers.

In this case, the slightly simpler ptr[i] is the i-th pointer in the
array.

Which one did you mean?
Remove del for email
Dec 6 '07 #6

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

Similar topics

3
2348
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ---------------------------------------------- //example 1: typedef int t_Array; int main(int argc, char* argv)
9
15714
by: sangeetha | last post by:
Hello, Is there any performance difference in using of the following two declaration? int (*ptr); //Array of 10 int pointers int *ptr; // pointer-to-array of 10. Regards, Sangeetha.
204
12984
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
7
2799
by: Kathy Tran | last post by:
Hi, Could you please help me how to declare an araay of pointer in C#. In my program I declared an structure public struct SEventQ { public uint uiUserData; public uint uiEvent; public uint uiParam0; public uint uiParam1;
15
3829
by: Paminu | last post by:
Still having a few problems with malloc and pointers. I have made a struct. Now I would like to make a pointer an array with 4 pointers to this struct. #include <stdlib.h> #include <stdio.h> typedef struct _tnode_t { void *content; struct _tnode_t *kids;
27
8949
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in advance. Erik
8
2229
by: Martin Jørgensen | last post by:
Hi, "C primer plus" p.382: Suppose we have this declaration: int (*pa); int ar1; int ar2; int **p2;
42
5313
by: xdevel | last post by:
Hi, if I have: int a=100, b = 200, c = 300; int *a = {&a, &b, &c}; than say that: int **b is equal to int *a is correct????
17
5244
by: Ivan K. | last post by:
I am looking at some legacy code, which begins by allocating a double matrix with the dmatrix() function from NRC as follows: double **A, **augin, **augout, **aa; A = dmatrix(1, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3); aa = dmatrix(1, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3); augin = dmatrix(1, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3+MAXSIMS); augout = dmatrix(1, MAXNSTU+1, 1, MAXCOV+MAXCOVLOC+3+MAXSIMS);
14
1978
by: Szabolcs Borsanyi | last post by:
Deal all, The type typedef double ***tmp_tensor3; is meant to represent a three-dimensional array. For some reasons the standard array-of-array-of-array will not work in my case. Can I convert an object of this type to the following type?
0
8312
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.