各项区别如下:
1、如果只是int a[10]和int* a=new int[10]比较的话,前者可能还更简单一点。只是在使用上int* a=new int[10]需要判断内存是否分配成功,以及在不用时需要使用delete[] a进行内存释放;
2、如果不是a[10],而是a[1000000000]或者更大的话,那一般情况下,就只能使用int* a=new这种方式了。这个涉及到内存存放位置的问题,int a[]这种方式,内存是存放在栈上;int* a=new这种方式,内存是存放在堆上,栈的实际内存是连续内存,因此可分配空间较小,堆可以是非连续内存,因此可以分配较大内存。因此,如果需要分配较大内存,需要分配在堆上;
3、使用int a[10]这种方式,内存大小需要用常量指定,比如这里的10。不能用int m=10;int a[m]这种方式。但是int* a= new这种方式可以,因此在动态分配内存上,后者有非常大的优势。
c++ :
C++是在C语言的基础上开发的一种通用编程语言,应用广泛。C++支持多种编程范式 --面向对象编程、泛型编程和过程化编程。最新正式标准C++14于2014年8月18日公布。其编程领域众广,常用于系统开发,引擎开发等应用领域,是至今为止最受广大程序员受用的最强大编程语言之一,支持类:类、封装、重载等特性。
相关文章
- c++中int a[10]和int a=new int[10]]有什么区别
- Java第三章习题3-7(1到n的阶乘和 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Administrator */ public class Find { public void main{ int n=9999; int sum=0; int k=1,i=1; for( i=1;i<=10;i++){ k=k*i; sum=sum+k; if(sum>9999){ break; } } (i-1); } } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Administrator */ public class Test { public static void main(String[] args){ Find f=new Find; ; } }
- 在java中,(int)(Math.random())和Math.random()之间有什么区别?
- Mysql中int(2)和int(10)的区别
- C#中(int)a和Convert.ToInt32(a)有什么区别
- C中的unsigned int和signed int有什么区别?
- 在c++中size_t和int有什么区别?
- 在C ++中创建指针数组的char *和int *数据类型有什么区别?
- 在java中,(int)(Math.random())和Math.random()之间有什么区别?
- 在c++中size_t和int有什么区别?