Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:09:13+00:00 2026-05-23T18:09:13+00:00

I have an array variable, say for an example:- int a[10]; And suppose i

  • 0

I have an array variable, say for an example:-

int a[10];

And suppose i have added 4 elements say 1,2,3,4 starting from a[0] till a[3].
Now how do i find that how much element is present in the array variable a whose max size is 10?

My way to obtain the number of elements present in the array assuming that user will give input greater than or equal to Zero:-

#include<iostream>
using namespace std;    
#define SIZE 10
int main(){
    int *a = (int*)malloc(sizeof(int)*SIZE);
    int iCount=0;
    int iNumberOfElements,iElements;
    cout<<"\nEnter the number of elements to be entered:";
    cin>>iNumberOfElements;
    cout<<"\nEnter the elements(Please enter elements greater than or equal to zero):\n";
    for (int jIndex = 0; jIndex < iNumberOfElements; jIndex++){ 
        cin>>iElements;
            while(iElements<0){
               cout<<"\nPlease enter the element greater than or equal to Zero.\nRe-enter:\n";
               cin>>iElements;
        }
        a[jIndex] = iElements;
    }
    for(int iIndex=0;iIndex<SIZE;iIndex++){
        if(a[iIndex] >= 0){ //I am checking in this way assuming that user will give input >= 0
            iCount++;
        }
    }
    cout<<"\nThe total number of element present in the array is:"<<iCount<<endl;
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:09:14+00:00Added an answer on May 23, 2026 at 6:09 pm

    You have to build in that convention yourself.

    For instance, you could initialize the whole array to some magic constant that signals “not in use”, or you could track the length through a separate variable.

    Either way, the framework will not help you at all, there is no way. For all intents and purposes, the array has 10 elements, whether you set them or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable that contains an array. That array contains X number of
Say I have 3 arrays of arrays and when I write in any of
Say you have two arrays (pseudo-code): arrayA = [ a, b, c, d ];
Say I have a class with multiple private String variables: public class Children {
I have a situation where I need to display ItemID and ItemName from Items
I find the practice of caching an array's length property inside a for loop
Let's say I have something like this: <?php namespace Twitter; class Twitter { function
I have a web server that is running PHP 5.3.6 non thread safe (VC9),
Let's set the stage, PHP & MYSQL: I have a table we'll call Directions
i know this would be probably too much to ask for . i am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.