473,386 Members | 1,706 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,386 software developers and data experts.

Wht you mean this declaration..

Hi all,

i come across the following declaration in some code.

int (*ptr)[ 10];

any feedback helps a lot for me.

Dec 7 '06 #1
3 1770

code break wrote:
Hi all,

i come across the following declaration in some code.

int (*ptr)[ 10];

any feedback helps a lot for me.
Find yourself a copy of "cdecl" :-

$ cdecl
Type `help' or `?' for help
cdeclexplain int (*x)[10]
declare x as pointer to array 10 of int
cdeclexplain int *x[10]
declare x as array 10 of pointer to int

Dec 7 '06 #2
ma**********@pobox.com wrote:
code break wrote:
Hi all,

i come across the following declaration in some code.

int (*ptr)[ 10];

any feedback helps a lot for me.

Find yourself a copy of "cdecl" :-
<off topic>

This is off-topic but OP might be using cdecl and facing a
parse error, thus leading to further confusion.
popular versions of cdecl treat "ptr" as a keyword. (short for
"pointer").

cdeclexplain int (*x)[10]
declare x as pointer to array 10 of int
cdeclexplain int (*ptr)[10]
parse error
cdeclexplain int (*foo)[10]
declare foo as pointer to array 10 of int
cdecl>

-p_cricket_guy

<-- snipped -->

Dec 7 '06 #3
code break wrote:
>
Hi all,

i come across the following declaration in some code.

int (*ptr)[ 10];

any feedback helps a lot for me.
It's a pointer to an array of ten int.
It can be used to access a two dimensional array
through a single pointer.

/* BEGIN new.c */

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

#define X 2
#define Y 10

int main(void)
{
int (*ptr)[Y];
int x, y;

ptr = malloc(X * sizeof *ptr);
if (ptr == NULL) {
puts("ptr == NULL");
exit(EXIT_FAILURE);
}
for (x = 0; x != X; ++x) {
for (y = 0; y != Y; ++y) {
ptr[x][y] = Y * x + y;
}
}
for (x = 0; x != X; ++x) {
for (y = 0; y != Y; ++y) {
printf("%2d ", ptr[x][y]);
}
putchar('\n');
}
free(ptr);
return 0;
}

/* END new.c */

--
pete
Dec 7 '06 #4

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

Similar topics

70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
11
by: Sier | last post by:
CL_ConsoleWindow console("Console"); Is this some c++ idiom or a macro? I know you can't tell without the headers, but I want a quick explanation.
1
by: elviin | last post by:
Hello. I'd like to know what means const() in the following declaration T & operator(std::ptrdiff_t i) const() const; I've been looking on http://boost.org/libs/smart_ptr/shared_array.htm
9
by: Thelma Lubkin | last post by:
I've been looking at code that handles string manipulation and I keep seeing variable names, and function names, too, followed by a '$'. I've also found a variable followed by a '%' symbol, but...
8
by: ranjeet.gupta | last post by:
warning C4013: 'localData' undefined; assuming extern returning int What the above warning exactly mean ?
39
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the...
2
by: Olaf \El Blanco\ | last post by:
19 ..\tipos.h previous declaration of 'ccc' was here 27 ..\tipos.h conflicting types for 'client' I have a lot...
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
2
by: king imran | last post by:
I am giving u complete code. It works properly But add max and mean functions so that it can work properly. * /LinkList.h/ * #include "Node.h" * /* The LinkList class declaration*/ class**...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.