Question

C++ for (double i=0; i<100000000; i++){ int *p = new int[100000000]; delete p; } Which of...

C++
for (double i=0; i<100000000; i++){
        int *p = new int[100000000];
        delete p;    
}
 

Which of the following statement(s) is/are correct?  

There is a run-time error

There is a syntax error

There is a memory leak

There is no error

Homework Answers

Answer #1

answer: option d) There is no error

EXPLANATION:

Since, double datatype also belongs from the family of integer datatype but having a higher size and range as compared to integer.

Therefore like integer varable, double variable is also iteratable in for loop and do not give any error.

For your understanding and confirmation, I have compiled this code on c++ compiler. As you can see that, the compiler doesnt give any error.

Know the answer?
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
Similar Questions
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i];...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i]; } return (double)sum/n; } Rewrite the function to eliminate the array subscripting (a[i]), using pointer arithmatic instead. Write a program that reads a line of input and checks if it is a palindrome (ignoring spaces) Write a program that takes the name of a file as a command line argument, and prints the contents of the file (similar to the linux 'cat' program). Write...
List the errors in the following array declarations. A. int intArray[] = new double[10]; B. int...
List the errors in the following array declarations. A. int intArray[] = new double[10]; B. int intArray[] = new int[1.5]; C. double[] doubleArray = new double[-10] D. int intMatrix[] [] = new int[10]; - Write a method selectRandom that expects an array of integers as a parameter. The method should return the value of an array element at a randomly selected position.
Here is a bit of Java code: Thing t = new Thing(); t.method( (int i)-> i...
Here is a bit of Java code: Thing t = new Thing(); t.method( (int i)-> i + 1 ); Here is a skeleton for class Thing: class Thing { public interface Mystery { ????? } public void method( Mystery param ) { // body of method omitted } } Which text below would work where ????? is given above: a) void method( int i ); b) int method( int i ); c) abstract int method( int i ); d) abstract...
Considering the following code fragment: #include<stdio.h> #include <stdlib.h> int base = 0; static int bonus; int*...
Considering the following code fragment: #include<stdio.h> #include <stdlib.h> int base = 0; static int bonus; int* demage (int dmg) { int* ptr = (int*) malloc(sizeof(int)); static int constant = 1;   *ptr = dmg + constant; return ptr; } int main() { int HP = 0; int* dm; base = 30; bonus = 20; for(int i=1; i<4; i++) { HP += i * base; } dm = demage(10); HP += bonus - *dm; printf("Total HP: %i", HP); return 0; } Please...
How would I write the following program in C programming language? Function header: int sumsort(int *a,...
How would I write the following program in C programming language? Function header: int sumsort(int *a, int *b, int *c) This function should arrange the 3 values in the memory locations pointed to by a, b, and c in ascending order and also return the sum of the contents of the memory locations a, b, and c.
I am experimenting with pointers in C. I wrote this code. int i1; int i2 =...
I am experimenting with pointers in C. I wrote this code. int i1; int i2 = 50; int *intptr1; int *intptr2; intptr1 = &i1; intptr2 = &i2; intptr1 = intptr2; printf("\nvalue of intptr1: %d\n", *intptr1); /*prints 50*/ dubptr1 = (double *)intptr1; printf("\nvalue of dubptr1: %f\n", *dubptr1); /*prints 0.0000*/ I would have expected the last statement to print 50.0000. Is it actually supposed to print 0.0000 or did I make a mistake somewhere and if I did please help me understand...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
int b = 4, p = 5, r = 2, v = 8; double x; Write...
int b = 4, p = 5, r = 2, v = 8; double x; Write the JAVA statement to perform the following: Assign x the value of p multiplied by v - 6 all divided by the square root of the sum of b and p
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using pointers correctly and deleting memory properly? #ifndef DYNAMICARRAY_H #define DYNAMICARRAY_H #include <cstdlib> #include <iostream> using namespace std; // Node class class Node { int data; Node* next; Node* prev; public: Node(); Node(int); void SetData(int newData) { data = newData; }; void SetNext(Node* newNext) { next = newNext; }; void SetPrev(Node* newPrev) { prev = newPrev; }; int getData() { return data; }; Node* getNext()...