Hi,
int *p;
p++; here p now increments itself with the size of integer.
similarly,
I wanted to know, how to declare an pointer to an array ( say array of
integers)
where in it we do a p++ it increments itself with the size of the
array each time it is incremented with 1.
like
p++; ie p = p + 1; // should increment with 10 if 10 is the size of
the array.
The pointer to an array, should increment the pointer with the size of
an array each time it is incremented with 1. Can we declare such a
pointers ?
one probable solution for this is
#define SIZE_ARRAY
int *p[SIZE_ARRAY][SIZE_ARRAY];
// to increment the pointer with the size of the array.
p = p + SIZE_ARRAY; // increment each time with the size.
but this does not declare a pointer to array as it simply moves to
next location if we do p = p + 1;
I know array is not the primitive data type. but is there a way to do
it ? 12 2243 sh***********@s ify.com wrote: int *p; p++; here p now increments itself with the size of integer.
similarly, I wanted to know, how to declare an pointer to an array ( say array of integers) where in it we do a p++ it increments itself with the size of the array each time it is incremented with 1. like p++; ie p = p + 1; // should increment with 10 if 10 is the size of the array.
The pointer to an array, should increment the pointer with the size of an array each time it is incremented with 1. Can we declare such a pointers ?
one probable solution for this is
#define SIZE_ARRAY int *p[SIZE_ARRAY][SIZE_ARRAY];
No, that would be a two-dimensional array of int pointers.
What you need is (I think) something like this:
int a[ SIZE_ARRAY_1 ][ SIZE_ARRAY_2 ];
int ( *p ) [ SIZE_ARRAY_2 ] = &a[ 0 ];
because that's a pointer to an int array of size SIZE_ARRAY_2.
p++ would than be a pointer to a[ 1 ] etc.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de sh***********@s ify.com wrote in message news:<62******* *************** ****@posting.go ogle.com>... Hi, int *p; p++; here p now increments itself with the size of integer.
No, p is incremented with the size of a data pointer. What you're
saying is sizeof(int) == sizeof(int *) which is not necessarily true,
and I don't think this is what you meant to say. similarly, I wanted to know, how to declare an pointer to an array ( say array of integers) where in it we do a p++ it increments itself with the size of the array each time it is incremented with 1. like p++; ie p = p + 1; // should increment with 10 if 10 is the size of the array.
Not possible. What you're asking for are custom-defined pointers.
Data pointers and function pointers are implementation defined, not
user defined.
You could use pointers to pointers ...
int *p[3];
Set *p[0], *p[1] and *p[2] to point to different arrays. Now p++ will
reference the start of each array in turn.
Regards,
Mark.
<sh***********@ sify.com> wrote in message
news:62******** *************** ***@posting.goo gle.com... Hi, int *p; p++; here p now increments itself with the size of integer.
similarly, I wanted to know, how to declare an pointer to an array ( say array of integers) where in it we do a p++ it increments itself with the size of the array each time it is incremented with 1. like p++; ie p = p + 1; // should increment with 10 if 10 is the size of the array.
The pointer to an array, should increment the pointer with the size of an array each time it is incremented with 1. Can we declare such a pointers ?
one probable solution for this is
#define SIZE_ARRAY int *p[SIZE_ARRAY][SIZE_ARRAY];
// to increment the pointer with the size of the array.
p = p + SIZE_ARRAY; // increment each time with the size.
but this does not declare a pointer to array as it simply moves to next location if we do p = p + 1; I know array is not the primitive data type. but is there a way to do it ?
struct p_size_array {int p[SIZE_ARRAY];};
A pointer of this (special limited case of) struct should then behave in the
method you have listed.
Michael Steve
Mark R.Bannister wrote: sh***********@s ify.com wrote in message news:<62******* *************** ****@posting.go ogle.com>...
Hi, int *p; p++; here p now increments itself with the size of integer. No, p is incremented with the size of a data pointer. What you're saying is sizeof(int) == sizeof(int *) which is not necessarily true, and I don't think this is what you meant to say.
No; `p' has advanced by sizeof(*p) == sizeof(int) bytes
(assuming it was pointing someplace valid to begin with).
sizeof(int*) doesn't come into the picture at all. similarly, I wanted to know, how to declare an pointer to an array ( say array of integers) where in it we do a p++ it increments itself with the size of the array each time it is incremented with 1. like p++; ie p = p + 1; // should increment with 10 if 10 is the size of the array.
Not possible.
Most definitely possible. Using typedefs for clarity
(this can be written without them):
typedef int Array[10];
Array x[2]; // x[0] is a ten-int array, x[1] another
Array *p = x; // p points to x[0]
++p; // p points to x[1], ten ints away
What you're asking for are custom-defined pointers. Data pointers and function pointers are implementation defined, not user defined.
I'm not sure what you're trying to say here. Pointers
(both kinds) are certainly "user-defined" in the sense that
the user can invent new data and function types and can then
form pointers to those types. The implementation defines
the way those pointers are represented, but that's a red
herring: The user is still able to build types and pointers
that the implementation has never heard of until his source
code came along.
-- Er*********@sun .com sh***********@s ify.com wrote: I wanted to know, how to declare an pointer to an array ( say array of integers) where in it we do a p++ it increments itself with the size of the array each time it is incremented with 1.
int (*p)[SIZE];
Note that the parentheses are important since without them you get an
array of pointers rather than a pointer to an array. Note also that
pointers to arrays are not usually useful except in conjunction with
multi-dimensional arrays.
-Larry Jones
These things just seem to happen. -- Calvin
Michael Steve <ms****@columbu s.rr.com> wrote: <sh***********@ sify.com> wrote in message one probable solution for this is
#define SIZE_ARRAY int *p[SIZE_ARRAY][SIZE_ARRAY];
// to increment the pointer with the size of the array.
p = p + SIZE_ARRAY; // increment each time with the size.
but this does not declare a pointer to array as it simply moves to next location if we do p = p + 1; I know array is not the primitive data type. but is there a way to do it ?
struct p_size_array {int p[SIZE_ARRAY];};
A pointer of this (special limited case of) struct should then behave in the method you have listed.
I wouldn't be sure - there are always those nasty padding bytes. As
far as I can see structures always have to start at an address that
is compatible with strictest alignment requirements on a machine to
be able to create arrays of them, so additional padding bytes might
be required. And then the size of an int array with SIZE_ARRAY ele-
ments could differ from the one of the structure.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
<Je***********@ physik.fu-berlin.de> wrote in message
news:2p******** ****@uni-berlin.de... Michael Steve <ms****@columbu s.rr.com> wrote: <sh***********@ sify.com> wrote in message one probable solution for this is
#define SIZE_ARRAY int *p[SIZE_ARRAY][SIZE_ARRAY];
// to increment the pointer with the size of the array.
p = p + SIZE_ARRAY; // increment each time with the size.
but this does not declare a pointer to array as it simply moves to next location if we do p = p + 1; I know array is not the primitive data type. but is there a way to do it ?
struct p_size_array {int p[SIZE_ARRAY];};
A pointer of this (special limited case of) struct should then behave in the method you have listed.
I wouldn't be sure - there are always those nasty padding bytes. As far as I can see structures always have to start at an address that is compatible with strictest alignment requirements on a machine to be able to create arrays of them, so additional padding bytes might be required. And then the size of an int array with SIZE_ARRAY ele- ments could differ from the one of the structure.
Regards, Jens -- \ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de \______________ ____________ http://www.toerring.de
A structures alignment is dictated by the first basic data type (and nested
structs) of the struct. In this case, it would be int. The structure is also
a multiple of size int. So the structure requires no padding if an array of
this structure were created. Since all the internal members of the struct
also fall on their respective alignments, no internal padding within is
necessary. So in this special limited case of struct, the sizes will
coincide.
He asked for a way. He didn't ask for a way that didn't cause headaches.
Thanks for the user beware.
Michael Steve
Michael Steve wrote: <Je***********@ physik.fu-berlin.de> wrote in message news:2p******** ****@uni-berlin.de...
Michael Steve <ms****@columbu s.rr.com> wrote:
struct p_size_array {int p[SIZE_ARRAY];};A pointer of this (special limited case of) struct should then behave in the method you have listed.
I wouldn't be sure - there are always those nasty padding bytes. As far as I can see structures always have to start at an address that is compatible with strictest alignment requirements on a machine to be able to create arrays of them, so additional padding bytes might be required. And then the size of an int array with SIZE_ARRAY ele- ments could differ from the one of the structure.
A structures alignment is dictated by the first basic data type (and nested structs) of the struct.
struct counterexample {
char c;
long double ld;
};
The "first basic data type" here is `char', yet the struct's
alignment requirement is at least as strict as that of a
`long double', and may be stricter.
In this case, it would be int. The structure is also a multiple of size int.
I guess you mean sizeof(struct p_size_array) is a multiple
of sizeof(int). This is probably true of most implementations ,
but is not guaranteed by the C Standard.
So the structure requires no padding if an array of this structure were created. Since all the internal members of the struct also fall on their respective alignments, no internal padding within is necessary. So in this special limited case of struct, the sizes will coincide.
Same comment: Probably true of most implementations , but
not guaranteed by the language itself.
-- Er*********@sun .com
Eric Sosman <Er*********@su n.com> wrote in message news:<41******* *******@sun.com >... typedef int Array[10]; Array x[2]; // x[0] is a ten-int array, x[1] another Array *p = x; // p points to x[0] ++p; // p points to x[1], ten ints away
Umm, Eric, your solution is (for all intents and purposes) identical
to mine!
If you recall the original question stated "int *p; p++; here p now
increments itself with the size of integer." This statement is not
true, and it assumes the following ...
int p[2];
assert( ( &p[1] - &p[0] ) == sizeof( int ) );
This isn't correct, yes p++ will advance such that it points to the
next integer, but you can make no assumptions about just how far the
pointer has advanced in memory. Like I say, this is implementation
defined.
Regards,
Mark. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Lawson |
last post by:
I know how to conver a string to an array of strings, but I need to convert an ascii string to an
array of integers (really unsigned chars). Eg,
$str ="ABC";
needs to convert to something like this:
$buf = array(0x41, 0x42, 0x43);
Anyone know how? I haven't been able to find a way.
|
by: Peter Stojkovic |
last post by:
I want store an integer-array of 1000 Values in a blob in a SQL-database.
I will do this every 10 Seconds.
How can I do this ????
What datatypes a have to use ???
Thanks
|
by: simonc |
last post by:
Is there an easy way of writing a number in 32 bit integer format into four
bytes of a file? I am experimenting with FilePut but I can only make it work
by defining a four byte array and doing some simple calculations to work out
from my integer what the individual values of the four bytes have to be.
Surely there must be a short cut to doing this?
And are there also any existing routines for converting a floating point
number into...
|
by: Sivaraman.S |
last post by:
Hi,
Can i pass integer array to methodInfo.Invoke(obj,args()). I am able to
pass only string array to this function. This is the code i have written.
Dim myType As Type = objClass.GetType()
Dim myMethod As MethodInfo = myType.GetMethod("strFnName")
myMethod.Invoke(objClass, Args)
here "strFnName" is the function name and args() is the string array. args()
|
by: Eric A. Johnson |
last post by:
I'm trying to figure out if there is any way to create a Property for a
private array member. I have tried it like this:
' Property for the length of a side
Public Property SideLength(ByVal sideNumber As Integer) As Integer
Get
Return mSideLength(sideNumber)
| |
by: anonymous |
last post by:
I have couple of questions related to array addresses. As they belong
to the same block, I
am putting them here in one single post. I hope nobody minds:
char array;
int address;
Questions 1:
Why cannot I do the following:
|
by: msosno01 |
last post by:
I have Java client that connects to C++ server. The client sends
integer in binary using DataOutputStream write function. I am reading
these data into buffer. I have to convert this buffer back into
integer, but I am not sure how to do it.
This is my code:
int32_t var1;
uint8_t buf;
|
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);
|
by: Bob Palank |
last post by:
' Given
Dim v(19) As Integer ' a 20 element array
Dim vSorted(19) As Integer
Dim i As Integer
' The array v() is filled with random numbers
|
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...
|
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,...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |