473,503 Members | 12,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1059
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
6419
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
697
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
2304
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
2646
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
1487
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
1763
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
2362
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
8862
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
2579
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
2139
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
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
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...
0
7449
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...
0
5562
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,...
0
3160
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
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.