473,836 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to know size of integer array?

11 New Member
Been bothering me so long, we can find the size of string array (array of char) but what is the way to find the size for integer array? I've tried using while loop until it find '\0' null character, it's stop whenever integer 0 is encountered, which is not what I want .. anyone please help me
Aug 3 '06
16 226612
shinelakshmanan
13 New Member
thank you for your answer, but what I need to find is the size of array (length of array of integer) maybe I said it not clear enough, sorry

I've used sizeof [n] but it returns me same value each time (4) I don't know why
where n is array of integer, which I assign numbers of integer into it

please help
If n is an integer,
sizeof(n) will always give 4,
but if n is an array of integers,
sizeof(n) will give (4*number of elements in n).
Aug 7 '06 #11
ssehgal2010
10 New Member
Hi

Getting integer array size is prettry simple
Lets say I have int array i[5]

then
sizeof(i)/sizeof(i[0]) will give me 5 i.e. the length of integer array
Aug 11 '06 #12
I see a miscommunicatio n. If the array is declared with an explicit size, as in a[5], the compiler knows it is an array and knows how big it is, so sizeof() returns the total size of the array. If the array is incompletely declared, as in a[] (commonly used for a parameter or a const-initialized array), then the compiler only knows that "a" is a POINTER, not the array itself, and the sizeof refers to the POINTER.
Oct 4 '10 #13
Bugdog
1 New Member
Are you sure? I do understand that it may depend on standards and how they are implemented by compilers, but when I declare an array like this:

const int arr[] = { 1,2,3,4,5,6,7,8 ,9,10 };

The sizeof(arr) gives me 4 * 10, provided that sizeof(int) in my system is 4.
Aug 24 '11 #14
Banfa
9,065 Recognized Expert Moderator Expert
@Bugdog you are correct, when you declare an array without specifying a size, i.e. when you actually are creating an array then the sizeof operator will give to correct size because the name actually is the name of an array.

when you using the [] notation in a function parameter list it is exactly the same as declaring a pointer (which can be treated very similarly to arrays). The name is a name of a pointer and not the name of an array and you get the size of the pointer if you use sizeof.
Sep 6 '11 #15
mukul
1 New Member
not necessary

this is compiler dependent

turboc assigns a size of 2 bytes to integer
Nov 8 '11 #16
lspxy
12 New Member
because the formal parameter when functions are called is just a copy of actual parameter, so sizof() is just a size of a pointer.
if the name of an array is operand of sizeof, then it returns the size of total array. so, it has some different.
Jan 2 '12 #17

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

Similar topics

6
2789
by: cxcodexc | last post by:
I am trying to overload the +, *, and - operators using variables of type int but allowing them to hold unlimited size. Can anyone help me do this? thanks
11
3616
by: Sontu | last post by:
Consider the following code: int main(void) { char buffer; func(buffer); } void func(char *bufpas) {
10
5243
by: Peter Stojkovic | last post by:
I want store an integer-array of 1000 Values in a blob in a SQL-database. I will do this every 10 Seconds. How can I do this ???? What datatypes a have to use ??? Thanks
1
2206
by: Sivaraman.S | last post by:
Hi, Can i pass integer array to methodInfo.Invoke(obj,args()). I am able to pass only string array to this function. This is the code i have written. Dim myType As Type = objClass.GetType() Dim myMethod As MethodInfo = myType.GetMethod("strFnName") myMethod.Invoke(objClass, Args) here "strFnName" is the function name and args() is the string array. args()
12
112114
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>
7
2734
by: rhitz1218 | last post by:
Hi all: Is it possible to store an integer array to another integer array? Or should I use an array of pointers that will point to a particular array? Thanks for the help.
5
2498
by: desktop | last post by:
I have a function that takes two pointers to an array. The first point to the first element while the other points to the last element. int nums = { 1, 2, 3, 4, 5, 7, 8, 9}; int* result; int end = (sizeof(nums)/4)-1; int s = 7; result = ::myfind(nums, nums + end, s);
16
3820
by: danieleghisi | last post by:
Hello I'm writing a small programme to look for some particular integer sets (homometric sets), and each one of this sets is a unsigned long long (e.g. {1, 2, 4, 7} --1001011=75). I need to have a very long list of sets of this kind, so I declared a #define MAXS = 397148160 static unsigned long long set;
18
5690
by: nk28 | last post by:
my question is that i have 512 mb ram .What is the max integer array size that i can declare in c. I recently experimented with different values and found that while i am able to create large values of array size the moment i use them i get "segmentation fault" error. All i know is that the answer is related to the actual stack size in my computer.. can someone help me???
0
9813
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
9661
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,...
0
10831
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10536
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7778
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
6976
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4446
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
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.