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

memory address question


int b [10] = {1,2,3,4,5,6,7,8,910};

b is a pointer that points to the first element. Does this mean that "b" is
stored is some other memory location. Assuming that the size of int is 4
bytes and size of the pointer is also 4 bytes, Does this mean that there
will be 44 bytes allocated after this statement? If yes, how can we get the
memory address where "b" is stored????? (&b doesnt work)

Thanx in advance.
Nov 16 '05 #1
2 948

b is a pointer that points to the first element. Does this mean that "b" is stored is some other memory location. Assuming that the size of int is 4
bytes and size of the pointer is also 4 bytes, Does this mean that there
will be 44 bytes allocated after this statement? If yes, how can we get the memory address where "b" is stored????? (&b doesnt work)


b is allocated on the stack. it is just 4 bytes (sizeof(void*)) on a 32 bit
platform.
so yes, there are 4 bytes on the stack and 40 on the heap.

&b should work. it could be that the compiler does not like this. in that
case it think you can
&(int*)b.

kind regards,
Bruno.
Nov 16 '05 #2
> b is allocated on the stack. it is just 4 bytes (sizeof(void*)) on a 32
bit
platform.
so yes, there are 4 bytes on the stack and 40 on the heap.


I am sorry to correct you, but this is not true. When using

int b [10] = {1,2,3,4,5,6,7,8,910};

there is no other object representing 'b' other than the array itself -
adress of b (&b) points to the same location as &( b[0] ), but it has
different type. I suggest reading some basic documentation about how arrays
work in C / C++.

Regards
Ondrej
Nov 16 '05 #3

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

Similar topics

4
by: C++fan | last post by:
Hi all: I have a question about memory allocation to an object of a class. For example, I define the following class: class example_class{ public: example_class(); void funtion_1();
32
by: John | last post by:
Hi all: When I run my code, I find that the memory that the code uses keeps increasing. I have a PC with 2G RAM running Debian linux. The code consumes 1.5G memory by the time it finishes...
20
by: Jonas | last post by:
Hi, I'm 99 % sure that Standard C guarantees to do a memory move inside realloc() in case the new, returned memory block (address) is different than the original one. Can any C expert confirm...
30
by: jimjim | last post by:
Hello, This is a simple question for you all, I guess . int main(){ double *g= new double; *g = 9; delete g; cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl; *g =...
11
by: Sushil | last post by:
Hi Gurus I've tried to come up with a small logical example of my problem. The problem is platform specific (MIPS) which I understand should not be discussed here. So here goes my example: ...
72
by: ravi | last post by:
I have a situation where i want to free the memory pointed by a pointer, only if it is not freed already. Is there a way to know whether the memory is freed or not?
15
by: puzzlecracker | last post by:
Got Confused on the interview with memory alligment questions... PLEASE HELP -- How much bytes of memory will structs below take on 32 bit machine? What about 64 bit machine? Why is it different?...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
20
by: sethukr | last post by:
hi, i need to store a value to a particular memory location without having a variable. So, how can i access a 'memory address' without using variables?? Is it possible in C??? Plz, help...
7
by: Virtual_X | last post by:
Hello why when we define a pointer for any type it takes a memory space such as the type it points to and it's just hold an address not data ex: int *x; int y; x=&y;
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.