473,749 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What does "int (*p)[3]" mean and how to use it?

I know int *p[3] mean an array of pointers to int, but I meet int
(*p)[3] which is confusing.
What does it mean and how to use it? Thanks for help.

Jan 1 '07 #1
12 8416
hn********@gmai l.com wrote:
I know int *p[3] mean an array of pointers to int, but I meet int
(*p)[3] which is confusing.
What does it mean and how to use it? Thanks for help.
int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

return EXIT_SUCCESS;
}

PS: Please look into the FAQ for better explanation.

Jan 1 '07 #2
is (*p)[?] equals to foo[?] here?
i can use (*p)[?] anywhere i used foo[?] ?
i mean can i replace all foo[?] with (*p)[?] as lang as i declared
"
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

"
p_***********@y ahoo.co.in wrote:
hn********@gmai l.com wrote:
I know int *p[3] mean an array of pointers to int, but I meet int
(*p)[3] which is confusing.
What does it mean and how to use it? Thanks for help.

int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

return EXIT_SUCCESS;
}

PS: Please look into the FAQ for better explanation.
Jan 1 '07 #3
p_***********@y ahoo.co.in said:

<snip>
>
int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;
So far so good...
printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);
printf can print void pointer values if you use %p, but that's it. So the
above line should read:

printf(" %p -- %p -- %p\n", (void *)(*p)[0],
(void *)(*p)[1],
(void *)(*p)[2]);

(Format to taste!)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 1 '07 #4
is (*p)[?] equals to foo[?] here?
i can use (*p)[?] anywhere i used foo[?] ?
i mean can i replace all foo[?] with (*p)[?] as lang as i stated
"
int (*p)[3];
int foo[3] = {0, 1, 2};

p = &foo;
"

p_***********@y ahoo.co.in wrote:
hn********@gmai l.com wrote:
I know int *p[3] mean an array of pointers to int, but I meet int
(*p)[3] which is confusing.
What does it mean and how to use it? Thanks for help.

int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

return EXIT_SUCCESS;
}

PS: Please look into the FAQ for better explanation.
Jan 1 '07 #5
Richard Heathfield wrote:
p_***********@y ahoo.co.in said:

<snip>

int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

So far so good...
printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

printf can print void pointer values if you use %p, but that's it. So the
above line should read:

printf(" %p -- %p -- %p\n", (void *)(*p)[0],
(void *)(*p)[1],
(void *)(*p)[2]);
Isn't (*p)[x] an int? Why do we need to print it as a pointer?
I may be missing something and unable to find out what it is.

Thanks.
>
(Format to taste!)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 1 '07 #6
Richard Heathfield wrote:
p_***********@y ahoo.co.in said:

<snip>
>int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

So far so good...
> printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

printf can print void pointer values if you use %p, but that's it. So the
above line should read:
Read the code again. It is not printing void pointer values. It is
printing int values. The code is perfectly correct.

p is pointer to array 3 of int
(*p) is array 3 of int, decays to pointer to int
(*p)[0] is int
printf(" %p -- %p -- %p\n", (void *)(*p)[0],
(void *)(*p)[1],
(void *)(*p)[2]);
Now this is wrong -- converting ints to void pointers is not a good idea.

--
Simon.
Jan 1 '07 #7
Simon Biber a écrit :
>
Read the code again. It is not printing void pointer values. It is
printing int values. The code is perfectly correct.

p is pointer to array 3 of int
(*p) is array 3 of int, decays to pointer to int
(*p)[0] is int
> printf(" %p -- %p -- %p\n", (void *)(*p)[0],
(void *)(*p)[1],
(void *)(*p)[2]);


Now this is wrong -- converting ints to void pointers is not a good idea.
Now, it is the 1st of January in the morning... Many people have a
hangover :-)
Jan 1 '07 #8
Simon Biber said:
Richard Heathfield wrote:
>p_***********@y ahoo.co.in said:
<snip>
>>
>> printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

printf can print void pointer values if you use %p, but that's it. So the
above line should read:

Read the code again. It is not printing void pointer values. It is
printing int values. The code is perfectly correct.
Oops, you're right. Careless of me.

My apologies to the OP, and to anyone who was misled.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 1 '07 #9
p_***********@y ahoo.co.in said:

<snip>
Isn't (*p)[x] an int? Why do we need to print it as a pointer?
I may be missing something and unable to find out what it is.
No, you're not missing anything - I am. Sorry about that. I completely
misread your printf.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 1 '07 #10

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

Similar topics

5
2834
by: Steven T. Hatton | last post by:
I've seen people here write that C++ doesn't support modules. What does that mean? 'Module' is a very nebulous term in my book. It probably means something quite different to me than what it does to people making that comment about C++. Can someone explain what they mean when they say C++ doesn't support modules? -- STH Hatton's Law: "There is only One inviolable Law" KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com...
9
4523
by: Marek Kurowski | last post by:
Yo! What mean when program is ALPHA or BETA version? I suppose it is not release version of program, but I don't know what it exactly mean. What it mean in your opinion? Marek Kurowski
4
3750
by: Luke Wu | last post by:
I am just wondering what the following terms usually mean: 1) "Standard C" 2) "K&R C" 3) "ANSI C" I am pretty sure "ANSI C" usually refers to the C89 standard, but what
5
2207
by: chandanlinster | last post by:
consider the program, /*********************************************************/ int main() { int a; printf("a = %u\n", a); printf("*a = %u\n", *a); return 0; }
9
76497
by: plusk1008 | last post by:
I have finals next week and I am stuck on one question on my review sheet for excel. So once again I beg: Please, please, please, please, please, please, please, please, please, please someone help me!! What does ### mean in Excel and how do you fix it??? please,please,please help!! 8( I'm totally stressed over this one question!! You can answer here or by email.
4
3731
by: chandanlinster | last post by:
hello everybody, as i was going through the "printf" man page, i came across this statement. printf("%*d", width, num); what does "*" mean?
4
3099
by: lander | last post by:
I've read the page life cycle thing in msdn, still, i'm getting a bit confused of thinking how all the things are going under the hood... I know that when page loading, that the controls' properties is populated and when page unloading, the resources are cleared. What I want to know is what's happening behind it, that is, from the perspective of the asp.net implementor.....I'm not sure whether i've stated clearly, hope you get it.
4
10823
by: david.karr | last post by:
I'm a CSS newbie, but I was browsing through the css files in the YUI library, and I noticed the following line: body {font:13px/1.231 arial,helvetica,clean,sans-serif;*font- size:small;*font:x-small;} I understand everything but the "/1.231". Is that something like a multiplier on the EM size? I can't find an example of that in the CSS spec.
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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,...
0
9566
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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,...
1
6800
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
6078
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
4608
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...
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.