Question

WRITE THE NECESSARY C++ STATEMENTS 1. (10 points) Allocate memory dynamically for an int array with 100 elements. Next, assig

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

#include <iostream>

using namespace std;

int main()
{
// Dynamically array created
int *arr = new int (100);
// Assigning value 1
for(int i =0; i < 100; i++){
arr[i] = 1;
}
// To print the array
for(int x = 0; x<100; x++){
cout<<arr[x];
}
//Deleting the array using delete key word
delete[] arr;
}

Add a comment
Know the answer?
Add Answer to:
WRITE THE NECESSARY C++ STATEMENTS 1. (10 points) Allocate memory dynamically for an int array with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • c++: Write a program to dynamically allocate memory for a C-style string on the heap for...

    c++: Write a program to dynamically allocate memory for a C-style string on the heap for up to 256 characters: Inside the main function: Allow the user to enter a word Pass the word to the function fun Write the function void fun(char *a) to: Print the word in Pig Latin. You can assume the word is all lowercase. The function should not alter the original array.

  • C Language Write the code that dynamically allocates an array of struct objects based on a...

    C Language Write the code that dynamically allocates an array of struct objects based on a size entered through the command line arguments, You will use the following struct and enum. typedef enum Color { RED, GREEN, BLUE } Color; typedef struct MyStruct { int value; Color color; } MyStruct; Write the code to do the following: a. Check for one additional command line argument. Only proceed to the rest of the program if it exists and that the value...

  • basic c++ 2. AC++ program contains the following C++ code (assume an int occupies 2 bytes...

    basic c++ 2. AC++ program contains the following C++ code (assume an int occupies 2 bytes each in memory): int x[ ] = { 10, 20, 30, 40, 50, 60, 70, 80); int *ptrx ptrx = x; Array x starts at memory location 2140. a. What is the value assigned to ptrx? b. What is the value of (x+2)? c. What is the value of *x? d. What is the value of (*x+2)? e. What is the value of *(x+2)?...

  • c++ please no global varaible write a value returning function input data to dynamically allocate a...

    c++ please no global varaible write a value returning function input data to dynamically allocate a short array of size elements and store the input data entered from the disk file into array.Return the base address of the array allocated.Read the data from the text file Hello.txt and store the data in reverse order in the array.the size of the data set will be in the file size 10 and the data was 1 2 3 4 5 6 7...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • using visual studio 2) For each of the following, write C++ statements that perform the specified...

    using visual studio 2) For each of the following, write C++ statements that perform the specified task.. (Ref: classwork named pointer2) a) Declare a built-in array of type unsigned int called values with five elements, and initialize the elements to the even integers from 2 to 10. b) Declare a pointer vPtr that points to a variable of type unsigned int. c) Write two separate statements that assign the starting address of array values to pointer variable vPtr. d) Use...

  • (a) Write a recursive function int find(const int A[], int n, int x); which returns the...

    (a) Write a recursive function int find(const int A[], int n, int x); which returns the first index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found. (b) Write a recursive function int rfind(const int A[], int n, int x); which returns the last index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found....

  • In C++ Create a class called MyInteger. It should have a field of type pointer-to-int called...

    In C++ Create a class called MyInteger. It should have a field of type pointer-to-int called pInteger. It should have a constructor that takes as a parameter an int - the constructor will then dynamically allocate memory for an int, using pInteger, and assign the parameter's value to that memory. The class should have a destructor that will deallocate that memory when the object is destroyed. You should write a copy constructor that will correctly make a separate copy of...

  • Computer science help why the c++defination has bug? float *arrayFt; arrayFt = new float(10); // allocate...

    Computer science help why the c++defination has bug? float *arrayFt; arrayFt = new float(10); // allocate an array of float for(int i = 0; i <= 10; i++) arrayFt[i] = 15.0; // initialize dynamic array delete arrayFt; // delete the allocated memory

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT