zoukankan      html  css  js  c++  java
  • (C/C++) Interview in English.


    Q: What is the difference between new/delete and malloc/free?
    A: Malloc/free do not know about constructors and destructors. New and delete create and destroy objects, while malloc and free allocate and deallocate memory.


    Q:What is difference between new and malloc?
    A: Both malloc and new functions are used for dynamic memory allocations and the basic difference is: malloc requires a special "typecasting" when it allocates memory for eg. if the
    pointer used is the char pointer then after the processor allocates memory then this allocated memory needs to be typecasted to char pointer i.e (char*).but new does not requires any
    typecasting. Also, free is the keyword used to free the memory while using malloc and delete the keyword to free memory while using new, otherwise this will lead the memory leak.

    Q: What is the difference between delete and delete[]?
    A: Whenever you allocate memory with new[], you have to free the memory using delete[]. When you allocate memory with 'new', then use 'delete' without the brackets. You use new[] to
    allocate an array of values (always starting at the index 0).


    Q: What is difference between malloc()/free() and new/delete?
    A: malloc allocates memory for object in heap but doesn't invoke object's constructor to initialize the object. new allocates memory and also invokes constructor to initialize the object. malloc()
    and free() do not support object semantics, does not construct and destruct objects, new and delete can be overloaded in a class "delete" first calls the object's termination routine (i.e. its destructor) and then releases the space the object occupied on the heap memory. If an array of objects was created using new, then
    delete must be told that it is dealing with an array by preceding the name with an empty []


    Q: What is the difference between "new" and "operator new" ?
    A:"operator new" works like malloc.


    Q: What is Memory alignment??
    A: The term alignment primarily means the tendency of an address pointer value to be a multiple of some power of two. So a pointer with two byte alignment has a zero in the least signi_cant bit.
    And a pointer with four byte alignment has a zero in both the two least signi_cant bits. And so on. More alignment means a longer sequence of zero bits in the lowest bits of a pointer.

  • 相关阅读:
    Android getMeasuredHeight()与getHeight()的区别
    Android控件属性android:visibility的"invisible"与"gone"的区别
    浅谈Android onClick与onLongClick事件触发的问题
    Android ListView中FooterView布局问题
    Android GridView 问题
    Android HTTP POST上传
    监听EditText实时输入
    C++03下的delegate实现-
    delegate委托的C++实现--C++11/14(原创)
    Unity3D 移动平台实现一种大规模(其实跟PC比还是算小规模)动画角色渲染的方案---绝对原创方案。。。
  • 原文地址:https://www.cnblogs.com/fdyang/p/4420247.html
Copyright © 2011-2022 走看看