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

Is it meaningful???

I just tried using an STL component in sizeof() and expected an error.
But, it compiled and it had printed an answer as follows...
Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. .
  4. #define show(x) cout<<#x<<" = "<<x<<endl
  5. vector<int> v1(5,0);
  6. show(sizeof(v1)/sizeof(int));//prints 3
  7. show(v1.size());// prints 5
  8. .
  9. .
Can anyone tell how or why?
Feb 7 '09 #1
1 1210
weaknessforcats
9,208 Expert Mod 8TB
v1.size() is the number of elements in the vector. vector must be implemented as an array so there are 5 elements in the array.

sizeof reports the amount of stack memory used. What leads you to believe the array is on the stack? I mean, the vector size is changeable but a stack array is not.

Read your vector template and you will see how much of it is on the stack. Most likely there is a pointer ti the array and maybe a counter for the number of elements.

It all means your sizeof calculation is meaningless.
Feb 7 '09 #2

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

Similar topics

3
by: windandwaves | last post by:
Hi, I am trying to make errors a bit more meaningful for my users. I am trying to fix error 3201 where there is a missing field in a form. If I do not do any error trapping, then I get ...
0
by: Joshua Ellul | last post by:
Hi, I am creating a web service that returns a double value.... if however, one of the user passed parameters are incorrect I would like to return to the user a meaningful message (rather than a...
24
by: Chad Everett | last post by:
Hey guys, I am back. Trying to expand on a program that was given in the book I am studying. No I am not a high school or college student. Doing this on my own. and having way to much...
12
by: Ron M. Newman | last post by:
hi, without going case-by-case, how do I know a "ToString" method returns useful information, like for Sytem.Int32, or useless information like for System.Drawing.Bitmap (returning the name of...
2
by: Srini | last post by:
Hi, Can anyone please tell me how to retrieve meaningful value from registry value in REG_Binary type? I tried to convert REG_Binary value to string using the following code.
7
by: Chuthu | last post by:
I'm writing a C program where the user enters a string and the program aims at finding whether the input string is meaningful English word or not. Comparing each and every input word with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.