473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to measure size of an array

Can anyone tell how to measure the size of an array without use of
sizeof operator ?

Feb 14 '07 #1
14 3379
"asit dhal" <pe********@gma il.comwrites:
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
How about referring to one of the many threads in the last few
months that discuss this same lame question, instead of starting
a new thread?
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Feb 14 '07 #2
On Feb 14, 9:02 am, "asit dhal" <penasit...@gma il.comwrote:
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
The size information is given at declaration of an array. When an
array is passed into a function, the sizeof can't evaluate the size of
the array inside the function.

Feb 14 '07 #3
asit dhal:
Can anyone tell how to measure the size of an array without use of
sizeof operator ?

(char*)pover - (char*)p

--
~/JB\~
Feb 14 '07 #4
"asit dhal" <pe********@gma il.comwrites:
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
Use the sizeof operator. That's what it's for.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 14 '07 #5
asit dhal wrote:
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
No.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Feb 14 '07 #6
lovecreatesbea. ..@gmail.com said:
On Feb 14, 9:02 am, "asit dhal" <penasit...@gma il.comwrote:
>Can anyone tell how to measure the size of an array without use of
sizeof operator ?

The size information is given at declaration of an array. When an
array is passed into a function, the sizeof can't evaluate the size of
the array inside the function.
You don't pass an array to a function. You pass a pointer to that
array's first element.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 14 '07 #7

"Jamie Boy" <a@b.cwrote in message n
>Can anyone tell how to measure the size of an array without use of
sizeof operator ?


(char*)pover - (char*)p

Make that unsigned char *.
char * should be reserved for genuine character data, and can contain trap
representations . A highly unlikely but allowable implementation could even
crash your program if one of the pointers points to a trap representation.
--
~/JB\~

Feb 14 '07 #8
"Malcolm McLean" <re*******@btin ternet.comwrite s:
"Jamie Boy" <a@b.cwrote in message n
>>Can anyone tell how to measure the size of an array without use of
sizeof operator ?
(char*)pover - (char*)p
Make that unsigned char *.
char * should be reserved for genuine character data, and can contain trap
representations . A highly unlikely but allowable implementation could even
crash your program if one of the pointers points to a trap representation.
I don't believe this. Can you cite chapter & verse on that?
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Feb 14 '07 #9
Malcolm McLean wrote, On 14/02/07 22:50:
"Jamie Boy" <a@b.cwrote in message n
>>Can anyone tell how to measure the size of an array without use of
sizeof operator ?

(char*)pover - (char*)p

Make that unsigned char *.
char * should be reserved for genuine character data, and can contain trap
representations . A highly unlikely but allowable implementation could even
crash your program if one of the pointers points to a trap representation.
What the pointers point to is irrelevant since they are not dereferenced
so casting to char* is fine. The problem with it is how you determine
the correct value of pover before you know the size of the array.
--
Flash Gordon
Feb 15 '07 #10

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

Similar topics

22
2449
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a nightmare. There are of course many solutions, but they all end up forcing you to abandon the array syntax in favour of macros or functions. Now I have two questions - one is historical, and the other practical. 1.) Surely malloc (and...
1
2140
by: Anand Ganesh | last post by:
Hi All, I have an image which is made to fit in a Window. The user can Zoom In or Zoom Out and Pan the image. These images are Engineering drawings which has been drawn to scale say 1 inch = 40 feet. Now I want to provide a tool for the user where he/she can measure the distance.
2
12358
by: AlirezaH | last post by:
How to measure hard disk capacity?
1
5973
by: Frank Rizzo | last post by:
I am doing some memory profiling work and I am trying to figure out the minimum size of an object. The object has a bunch of variables that are other objects (hashtables, array lists, and whatnot). How can I measure the size of such an object? C# provides a sizeof operator, but only for value types. Regards, Robert
5
1393
by: Joe Fallon | last post by:
Is there a good way to measure the size of a page delivered to the browser? Also, how do measure the size of Viewstate? I am just using View Source, saving the text file and looking at the number of kb in the Properties of the file. Then I delete everything but the viewstate and measue it the same way. 1. Is it accurate? 2. Is there a better way? (I want to measure over 100 pages.) --
12
1611
by: Crirus | last post by:
I need to measure how long a function take to execute... or a sequence of code within -- Ceers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you
12
112089
by: manochavishal | last post by:
Hi, I have a question. How can i know the size of array when it is passed to a function. For Example i have this code: #include <stdio.h> #include <stdlib.h>
6
14329
by: Scirious | last post by:
People, how can I know how big an object is? I mean, I have an object the collects data from a stream and when it grows to an especific size I need to create a new object to continue collecting the data and send the other one to a thread that records it's content to the disk. How do I do such thing? TIA, Scirious.
3
3412
by: Neagu, Adrian | last post by:
Hello everybody, I try to solve the following problem: I have a python program that takes a lot of memory (>hundred Mb). I made an improvement (I hope) and I want to measure the gain (if possible on several platforms). I would like to be able to print the max memory taken during the run upon exiting my Python program (like I already do for the time taken to run). I can see the total process size of the Python process (Task manager on...
0
8399
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, 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...
0
8312
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,...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
agi2029
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...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
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...

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.