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 6215925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:08:37+00:00 2026-05-24T07:08:37+00:00

// rememb-o-matic #include <iostream> #include <new> using namespace std; int main () { int

  • 0
 // rememb-o-matic
 #include <iostream>
 #include <new>
 using namespace std;

 int main ()

 {
   int i,n;
   int * p;
   cout << "How many numbers would you like to type? ";
   cin >> i;
   p= new (nothrow) int [i];
   if (p == 0)
     cout << "Error: memory could not be allocated";
   else
   {
     for (n=0; n<i; n++)
     {
       cout << "Enter number: ";
       cin >> p[n];
     }
     cout << "You have entered: ";
     for (n=0; n<i; n++)
       cout << p[n] << ", ";
     delete[] p;
   }
   return 0;
 }

Now,

why is their a bracket enclosed in variable i?

 p= new (nothrow) int [i];

why are their 2 for statements and what does a for statement do exactly?

Why is it deleting []p instead of the variable p?

  • 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-24T07:08:38+00:00Added an answer on May 24, 2026 at 7:08 am

    why is their a bracket enclosed in variable i? &
    Why is it deleting []p instead of the variable p?

     p= new (nothrow) int [i];
    

    Dynamically Allocates an int array of i elements .

     delete []p;
    

    Deletes the dynamically allocated array.


    Basic Rules of dynamic allocation in C++ are:

    • If you use new to dynamically allocate memory, Use delete to deallocate it.
    • If you use new [] to dynamically allocate memory, Use delete [] to deallocate it.

    Also, note that you are using nothrow version of the new operator, it basically returns a null if some error condition and does not throw an exception, this allows the C++ code to be compatible with the legacy c code which uses null check after memory allocations(malloc returns null on failure).


    what does a for statement do exactly?

    A for statement is a conditional loop construct, It keeps on executing the loop untill the condition remains true. The basic syntax of for loop is:

    for(;condition;)
    { 
        //doSomething
    }
    

    why are their 2 for statements?
    The first for loop in your code gets the input from the user. It takes the input for i times.

    The second for loop prints out the contents of the array.


    Suggest you to pick up a good C++ book and read through the basics to understand more.

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

Sidebar

Related Questions

PIXELFORMATDESCRIPTOR pfd = { /* otherwise fine for a window with 32-bit color */
I have a simple login form. When I click Login, the a4j:commandButton works well

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.