c语言100位整数变量声明_C ++程序动态声明一个整数变量并打印其内存地址
c語言100位整數(shù)變量聲明
Here, we will learn how we can declare an integer variable dynamically and how to print address of declared memory block?
在這里,我們將學(xué)習(xí)如何動態(tài)聲明整數(shù)變量,以及如何打印聲明的內(nèi)存塊的地址?
In C++ programming, we can declare memory at run time for any type variable like char, int, float, integer array etc. To declare memory at run time (dynamically), we use new operator. I would recommend reading about new operator first.
在C ++編程中,我們可以在運行時為char,int,float,integer array等任何類型的變量聲明內(nèi)存。要在運行時(動態(tài))聲明內(nèi)存,請使用new運算符。 我建議先閱讀有關(guān)新運算符的信息 。
Consider the following program:
考慮以下程序:
#include <iostream>using namespace std;int main() {//integer pointer declartion//It will contain the address of dynamically created //memory blocks for an integer variable int *ptr;//new will create memory blocks at run time //for an integer variableptr=new int;cout<<"Address of ptr: "<<(&ptr)<<endl;cout<<"Address that ptr contains: "<<ptr<<endl;//again assigning it run timeptr=new int;cout<<"Address of ptr: "<<(&ptr)<<endl;cout<<"Address that ptr contains: "<<ptr<<endl;//deallocating...delete (ptr);return 0; }輸出量 (Output)
Address of ptr: 0x7ffebe87bb98Address that ptr contains: 0x2b31e4097c20Address of ptr: 0x7ffebe87bb98Address that ptr contains: 0x2b31e4098c50Here we are declaring an integer pointer ptr and printing the address of ptr by using &ptr along with stored dynamically allocated memory block.
在這里,我們聲明的整數(shù)指針PTR以及通過使用&PTR與存儲動態(tài)分配的存儲塊沿著打印PTR的地址。
After that we are declaring memory for integer again and printing the same.
之后,我們再次聲明整數(shù)的內(nèi)存并打印該整數(shù)。
From this example - we can understand memory blocks are allocating dynamically, each time different memory blocks are storing in the pointer ptr.
從這個例子中,我們可以理解每次將不同的存儲塊存儲在指針ptr中時,存儲塊都是動態(tài)分配的。
翻譯自: https://www.includehelp.com/code-snippets/cpp-declare-integer-variable-dynamically-print-the-memory-addresses.aspx
c語言100位整數(shù)變量聲明
總結(jié)
以上是生活随笔為你收集整理的c语言100位整数变量声明_C ++程序动态声明一个整数变量并打印其内存地址的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 离散数学和组合数学什么关系_关系类型|
- 下一篇: 一串字符串转换为ascii_将ASCII