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

how is size of pointer calculated?

char *ptr;

sizeof(*ptr) will return you 1 (size of char varaible whose address it can hold).

char *ptr[10];

sizeof(*ptr) will return you 4 why???

Please clear my doubt regarding pointer
Jun 25 '10 #1
1 1651
Banfa
9,065 Expert Mod 8TB
char *ptr[10] is an array of 10 pointers to char.

*ptr, as with any array is equilivent to the first member of the array, ptr[0]. Since ptr is an array of 10 pointers to char ptr[0] is a pointer to char (char*) so *ptr is a pointer to char (char*).

Therefore sizeof(*ptr) == sizeof(ptr[0]) == sizeof(char *) which on you machine (which I assume is a 32bit machine) is 4 bytes.
Jun 25 '10 #2

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

Similar topics

3
by: chris | last post by:
Hi All, I have a style sheet which for reason I wont bore you all to sleep with needs to have EM fonts, to ensure a users can still alter the text size through their browser. Within the style...
6
by: Cheng Mo | last post by:
I tried in g++ sizeof(int*) siezof(long*) sizeof(Foo*)//Foo is a self-defined class They all has same size. Do all pointers have same size in a given platform with given compiler? Thanks &...
9
by: pvinodhkumar | last post by:
The number of elemets of the array, the array bound must be constant expression?Why is this restriction? Vinodh
19
by: junky_fellow | last post by:
Can the size of pointer variables of different type may be different on a particular architecture. For eg. Can the sizeof (char *) be different from sizeof(int *) or sizeof (void *) ? What...
7
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
20
by: junky_fellow | last post by:
Hi, In my previous post I asked if sizeof may be implemented as a function. Somebody pointed a link that says that sizeof may calculated as follows with a warning that it is not guaranteed to...
11
by: !truth | last post by:
Hi, i feel confused about the following program, and it's works to get a pointer-member's address. #define NETDEV_ALIGN 32 #define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1) ...
7
by: barcaroller | last post by:
Does a list<Tkeep track of its size or is the size re-calculated every time you call list<T>.size()?
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.