Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Consider the following snippet,

#include<iostream>
#include<stdlib.h>
int main(void)
{
int a[] = {1,2};
a =new int[2];
delete(a);
return 0;
}

This gives an error error: incompatible types in assignment of ‘int*’ to ‘int [2]’. I am statically creating an array of int . a is a pointer(it is of type int[2]) but it can't be used to point to other dynamically allocated arrays because they return pointer of type int*.

If you want to create an array dynamically you have to assign its address to a float*

float * a = new float[10] ;

Refer this this too.

Consider the following snippet,

#include<iostream>
#include<stdlib.h>
int main(void)
{
int a[] = {1,2};
a =new int[2];
delete(a);
return 0;
}

This gives an error error: incompatible types in assignment of ‘int*’ to ‘int [2]’. I am statically creating an array of int . a is a pointer(it is of type int[2]) but it can't be used to point to other dynamically allocated arrays because they return pointer of type int*.

If you want to create an array dynamically you have to assign its address to a float*

float * a = new float[10] ;

Refer this too.

Consider the following snippet,

#include<iostream>
#include<stdlib.h>
int main(void)
{
int a[] = {1,2};
a =new int[2];
delete(a);
return 0;
}

This gives an error error: incompatible types in assignment of ‘int*’ to ‘int [2]’. I am statically creating an array of int . a is a pointer(it is of type int[2]) but it can't be used to point to other dynamically allocated arrays because they return pointer of type int*.

If you want to create an array dynamically you have to assign its address to a float*

float * a = new float[10] ;

Refer this too.

Post Undeleted by Suvarna Pattayil
added 268 characters in body
Source Link
Suvarna Pattayil
  • 5.3k
  • 5
  • 35
  • 60

Consider the following snippet,

float#include<iostream>
#include<stdlib.h>
int myIDs[]main(void)
{
int a[] = {1,2};

a =new //Variablesint[2];
}delete(a);
return 0;
}

This declaresgives an error error: incompatible types in assignment of ‘int*’ to ‘int [2]’. I am statically creating an array of floatsint . The array name(is likea is a const pointer)(it is associated with only this memory location andof type int[2]) but it can't be used to point to other dynamically allocated arrays because they return pointer of type int*.

You can useIf you want to create an array dynamically you have to assign its address to a float* arrayName = new float[10]; etc to point to float arrays

float * a = new float[10] ;

Refer this too.

float myIDs[] = {
 //Variables
}; 

This declares an array of floats. The array name(is like a const pointer) is associated with only this memory location and can't be used to point to other arrays.

You can use float* arrayName = new float[10]; etc to point to float arrays

Consider the following snippet,

#include<iostream>
#include<stdlib.h>
int main(void)
{
int a[] = {1,2};

a =new int[2];
delete(a);
return 0;
}

This gives an error error: incompatible types in assignment of ‘int*’ to ‘int [2]’. I am statically creating an array of int . a is a pointer(it is of type int[2]) but it can't be used to point to other dynamically allocated arrays because they return pointer of type int*.

If you want to create an array dynamically you have to assign its address to a float*

float * a = new float[10] ;

Refer this too.

Post Deleted by Suvarna Pattayil
Source Link
Suvarna Pattayil
  • 5.3k
  • 5
  • 35
  • 60
float myIDs[] = {
 //Variables
}; 

This declares an array of floats. The array name(is like a const pointer) is associated with only this memory location and can't be used to point to other arrays.

You can use float* arrayName = new float[10]; etc to point to float arrays

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /