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

how to find max size for array in turbo c

satyanagendra
Hi
please tell me how to find max size of array in turbo c
if any body know about this please give me reply
Jul 6 '07 #1
3 3691
r035198x
13,262 8TB
Hi
please tell me how to find max size of array in turbo c
if any body know about this please give me reply
Let me ask you a question. What is the data type used as for indices of arrays? If you get that then the maximum size of an array can be found easily.
Jul 6 '07 #2
hi we can get the maximam size of an array as follows
u can get the total memory of an array using sizeof()
then dividing by ur datatype memory size u will get the maximam no of elements in an array
Jul 6 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
Be careful of this:
hi we can get the maximam size of an array as follows
u can get the total memory of an array using sizeof()
then dividing by ur datatype memory size u will get the maximam no of elements in an array
This only works if the array is a local stack variable:
Expand|Select|Wrap|Line Numbers
  1. int arr[10];
  2. int numelements = arr / sizeof(arr[0]);     //calculates numelements as 10
  3.  
However, if the array is a heap array:
[code=cpp]
int* arr = new int[10];
cout << sizeof( arr) / sizeof(arr[0]) << endl; //displays 1
That's because arr is a pointer. sizeof the pointer is 4. sizeof( arr[0]0 is als0 4. This situation occurs when you pass an array to a function. All that's passed is the address of the array. So inside a function sizeof( arr) / sizeof(arr[0] will always result in 1.

Expand|Select|Wrap|Line Numbers
  1. void fx(int* arr)
  2. {
  3. cout << sizeof arr / sizeof(arr[0]) << endl;  //always displays 1.
  4. }
  5.  
  6. int main()
  7. {
  8.     int* arr = new int[10];
  9.     cout << sizeof arr / sizeof(arr[0]) << endl;
  10.     fx(arr);
  11. }
  12.  
Jul 6 '07 #4

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

Similar topics

13
by: Noah Spitzer-Williams | last post by:
Hello guys, I would like to do something seemingly simple: find out if an element in an array that is passed to my function exists. I used to think I could just do: if (arr) ... However, if...
13
by: Ayaz Ahmed Khan | last post by:
Can a variable containing, say, an integer value be used as size declarator for an array of integers? g++ does not complain, but other compilers, such as Visual C++/6.0, Borland Builder C++, Turbo...
11
by: Sontu | last post by:
Consider the following code: int main(void) { char buffer; func(buffer); } void func(char *bufpas) {
5
by: nmtoan | last post by:
Hi, I could not find any answer to this simple question of mine. Suppose I have to write a program, the main parts of it are as follows: #include <blahblah.h> struct {
4
by: yahoo354 | last post by:
thats what i study in my theorotical books. But i am confused and bowled!!! Turbo C on XP.....sizeof int = 2 visual c++ on XP..sizeof int = 4 turbo C++ on XP ...size of int =4
2
choke
by: choke | last post by:
I need to write a function in devc++ that creates an array of n integers, each element is equal to n*n+i*i-n*i where i is from 0 to n-1 as the array index. Within the same function I need to find...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
25
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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?
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...
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
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.