473,325 Members | 2,805 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,325 software developers and data experts.

Can the base address be the smaller than the first element in an array?

74 64KB
Hello Everyone,

I know it might be a basic question, but I am just curious if you find out that the base address of an element is less than the actual number stored in array, is this taken in to account that your base address could be wrong for that element?
Sep 27 '17 #1
1 1709
chaarmann
785 Expert 512MB
Java starts counting with 0, as C does (in opposition to Basic).
So if you have variable myA that is an array of 5 elements (each 10 bytes big) then you can store the addresss of the first element in myA (let's say memory location 1000). So to access myA[3] you can just compute the address of this fourth element in memory by 1000 + 3 * 10 = 1030
That means myA+currentIndex*elementSize

This is quicker than accessing a one-based array with
a + (3 - 1) * 10
That means myA+(currentIndex - 1)*elementSize. And also you must check for illegal given index=0 before.
Sep 28 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: ehames | last post by:
Hi guys, As far as I know, for any type T, and positive integer N, if I have an array declared as: T array; then, &array and array are the same element. Is there any reason why a
7
by: ashu | last post by:
look at code #include<stdio.h> int *mult(void); int main(void) { int *ptr,i; ptr=mult; for(i=0;i<6;i++) { printf("%d",*(ptr++));
9
by: Wondering Wanderer | last post by:
hi, If I declare a character array ( say, char arr ), how do I see the address of the first element of the array ? simply using cout << arr or cout << &arr displays the entire string in the...
4
by: John den Haan | last post by:
Hello! I was wondering how I can pass a pointer to a 2D-array (declared with a malloc-construct) as if it were a continuous 1D-array of the size (rows*cols)? Is this at all possible, and if so,...
10
by: Chris Forone | last post by:
Hello Group, there is some memberfunc for std::valarray to return a pointer to the first element in the array. How do i use this? Thanx a lot. HAND Chris
7
by: Szabolcs Borsanyi | last post by:
I know that this topic has been discussed a lot, still I'd appreciate a clear cut (and correct) answer: I pass a multidimensional array to a function, which is defined as int f(int a) { int...
4
by: nembo kid | last post by:
I have the following bidimensional array int a ; Why the first address of this array is only: & (mat) and not also:
6
by: CSharper | last post by:
I am trying to use the following; I have an array with bunch of values in it. I am trying to find a value that contains part of the string I am passing eg string array = {"help","Csharp rocks"} ...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
5
by: dopiotrko | last post by:
Is it possible to change the address of one element of int table? My program would be much simpler, if the first element of the table would be same as last one. I mean: int *s;...
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
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.