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] ;
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.
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.
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