473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Declaration syntax

int* p[10] would mean that p is an array of 10 pointers to int.

I was a little puzzzled when I came across the following:

int (*p)[10];
What exactly does this one mean?
Thank you for your time.
Jul 22 '05 #1
2 1454
On 9 Apr 2004 16:16:25 -0700, lr******@yahoo.co.in (LRS Kumar) wrote:
int* p[10] would mean that p is an array of 10 pointers to int.

I was a little puzzzled when I came across the following:

int (*p)[10];
What exactly does this one mean?
p is a pointer to an array of 10 ints.

The vast majority of the times when you wish to point to an array, you do
it by defining a pointer to the element type, and setting that pointer to
point to the first element of the array:

int a[10];
int *pi;
...
pi = a; // same as: pi = &a[0];

Using a bona-fide pointer-to-array comes into use more when having to point
to multi-dimensional arrays, which C/C++ does not support in any especially
friendly way. I could not find one example (and I tried for a while) of
when a pointer to a 1-dimensional array of T's would be preferable to just
using a pointer-to-T, but I've no doubt there must be at least one
somewhere (well, almost no doubt; if no one provides an example here, try
comp.lang.c). In the meantime, for a good tutorial document on declarations
that includes quite a bit more than you'd typically expect to find on
pointer-to-arrays, check this out:
http://www.djmnet.org/lore/c-declarations.txt

HTH,
-leor


Thank you for your time.


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
On 9 Apr 2004 16:16:25 -0700, lr******@yahoo.co.in (LRS Kumar) wrote:
int* p[10] would mean that p is an array of 10 pointers to int.

I was a little puzzzled when I came across the following:

int (*p)[10];
What exactly does this one mean?
p is a pointer to an array of 10 ints.

The vast majority of the times when you wish to point to an array, you do
it by defining a pointer to the element type, and setting that pointer to
point to the first element of the array:

int a[10];
int *pi;
...
pi = a; // same as: pi = &a[0];

Using a bona-fide pointer-to-array comes into use more when having to point
to multi-dimensional arrays, which C/C++ does not support in any especially
friendly way. I could not find one example (and I tried for a while) of
when a pointer to a 1-dimensional array of T's would be preferable to just
using a pointer-to-T, but I've no doubt there must be at least one
somewhere (well, almost no doubt; if no one provides an example here, try
comp.lang.c). In the meantime, for a good tutorial document on declarations
that includes quite a bit more than you'd typically expect to find on
pointer-to-arrays, check this out:
http://www.djmnet.org/lore/c-declarations.txt

HTH,
-leor


Thank you for your time.


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3

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

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
2
by: Nils Emil P. Larsen | last post by:
Hello I have read about a C shared library which I want to use in my C program. (It's a library to encode/decode packets from/to a serial bus running with the SNAP-protocol). Unfortunatly...
10
by: Adam Warner | last post by:
Hi all, Just before Christmas Chris Torek gave me some great advice about closures in C: <http://groups.google.co.nz/groups?selm=cqcl3k030vj%40news3.newsguy.com&output=gplain> It includes this...
9
by: Michael Mair | last post by:
Hello, in C89 (at least in the last public draft), "3.6.2 Compound statement, or block", we have ,--- | Syntax | | compound-statement: | { ...
3
by: Wild Wind | last post by:
Hello, I made a post relating to this issue a while back, but I haven't received any answer, so here I am again. I am writing a mixed C++ dll which uses the following declaration: typedef...
4
by: Alan Foxmore | last post by:
Hi everyone, I'm new to C# and I was hoping I could get some clarification on the syntax for jagged and multidimensional arrays. Here is my question: The following syntax is correct for...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
2
by: Alan | last post by:
Does a template class declaration, like template <class T> have to come immediately prior to the declaration of the function, e.g., T do_something (T something) { . . . } that uses it?
16
by: Anil Gupte/iCinema.com | last post by:
Can someone please explan the difference between Dim temp as String() and Dim temp() as String in terms of syntax and practical usage? I thought I knew, but of late have become confused...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.