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

  • SEARCH
  • Home
  • 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 6011021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:11:59+00:00 2026-05-23T02:11:59+00:00

int main() { clrscr(); int x[3]; int n; cout<<Enter the array size= ; cin>>n;

  • 0
int main()
{
    clrscr();
    int x[3];
    int n;
    cout<<"Enter the array size= ";
    cin>>n;
    cout<<"Enter the elements for array= ";
    for(int i=0;i<n;i++)
    {
        cin>>x[i] ;
    }
    for(i=0;i<n;i++)
    {
        cout<<"x["<<i<<"]="<<x[i]<<"\n";
    }
    getch();
    return 0;
}

When m trying the same logic in c# then I got the right output as if I enter the size of array more than I initialize it gives the exception. But in c++ m not getting any type of error neither on compilation time nor at run time. But according to rule it should be give some error at run time in output if i give array size more than I initialize. And one thing more why it determine the 09 as two numbrs not single as 90 it shows it 0 and 9 at differect index as in output.

output

enter image description here

  • 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-23T02:11:59+00:00Added an answer on May 23, 2026 at 2:11 am

    If you have an array:

    char array[3];
    

    And you try to write into an element that doesn’t exist:

    array[15] = '!';
    

    Then this is an error. However, a compiler is not required by the C++ Standard to diagnose this error, and most do not. This is because it would require computation every time you accessed the array to determine whether you were within the array bounds.

    Instead, it is up to the programmer to ensure that he/she uses the array correctly, by writing these bounds checks his- or herself. Then the checks are only performed when the programmer has deemed them necessary, and there are no wasted computations.

    So:

    std::cin >> n;
    
    if (n > 3)
       throw std::runtime_error("OMG not enough space in my array!");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int main() { clrscr(); char c[80],d[80]; cout<<Enter a string = ; cin.get(a,80); strcpy(c,a); strrev(a);
int main(void) { char tmp, arr[100]; int i, k; printf(Enter a string: ); scanf_s(%s,
int main() { int (*x)[5]; //pointer to an array of integers int y[6] =
int main() { int *d=0; printf(%d\n,*d); return 0; } this works fine. >cc legal.c
test.c: int main() { return 0; } I haven't used any flags (I am
int main ( ) { char C[] = Hello World; write(0,C,sizeof(C)); return 0; }
int main() { int i=3; (i << 1); cout << i; //Prints 3 }
int main() { int a[3]={1,10,20}; printf(%u %u %u \n ,&a,a,&a[0]); return 0; } This
#include<stdio.h> #include<conio.h> #include<iostream.h> void main() { int wh=1,i,j; int sale[5][3]; clrscr(); for(i=1;i<=5;i++) { for(j=1;j<=3;j++)
#include <stdio.h> #include <conio.H> void main() { int a,b,c,d,e,f,g,i,h; float p; char A[10]; clrscr();

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.