c語言100位整數變量聲明_C ++程序動態聲明一個整數變量并打印其內存地址

c語言100位整數變量聲明

Here, we will learn how we can declare an integer variable dynamically and how to print address of declared memory block?

在這里,我們將學習如何動態聲明整數變量,以及如何打印聲明的內存塊的地址?

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等任何類型的變量聲明內存。要在運行時(動態)聲明內存,請使用new運算符。 我建議先閱讀有關新運算符的信息 。

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 variable
ptr=new int;
cout<<"Address of ptr: "<<(&ptr)<<endl;
cout<<"Address that ptr contains: "<<ptr<<endl;
//again assigning it run time
ptr=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: 0x2b31e4098c50

Here we are declaring an integer pointer ptr and printing the address of ptr by using &ptr along with stored dynamically allocated memory block.

在這里,我們聲明的整數指針PTR以及通過使用&PTR與存儲動態分配的存儲塊沿著打印PTR的地址。

After that we are declaring memory for integer again and printing the same.

之后,我們再次聲明整數的內存并打印該整數。

From this example - we can understand memory blocks are allocating dynamically, each time different memory blocks are storing in the pointer ptr.

從這個例子中,我們可以理解每次將不同的存儲塊存儲在指針ptr中時,存儲塊都是動態分配的。

翻譯自: https://www.includehelp.com/code-snippets/cpp-declare-integer-variable-dynamically-print-the-memory-addresses.aspx

c語言100位整數變量聲明

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540451.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540451.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540451.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[轉載] python 函數返回多個值

參考鏈接&#xff1a; 在Python中返回多個值 &#xff08;廖雪峰Python教程學習筆記&#xff09; 函數體內部的語句在執行時&#xff0c;一旦執行到return&#xff0c;函數就執行完畢&#xff0c;并將結果返回。 如果沒有return語句&#xff0c;函數執行完畢后也會返回結果…

二.編寫第一個c#程序(注釋,命名空間,類,Main方法,標識符,關鍵字,輸入,輸出語句,)...

復習編寫一個控制臺應用程序&#xff0c;目標是在控制臺輸出“Hello World” 1.第一步&#xff0c;打開Visual Studio 2012以上版本(我用的是VS 2015)&#xff0c;打開完成后出現以下界面 2.第二步&#xff0c;這時候就要新建一個解決方案了&#xff0c;創建解決方案可以直接點…

[轉載] Python中定義函數,循環語句,條件語句

參考鏈接&#xff1a; Python中的局部函數 由于日常程序流中主要是三種結構&#xff1a;順序&#xff0c;循環&#xff0c;條件&#xff0c;且往往需要自定義函數再調用&#xff0c; 因此今天想學習一下Python中關于定義函數、循環語句和條件語句的寫法。 1.定義函數 區…

node oauth2驗證_如何設置和使用護照OAuth Facebook身份驗證(第1部分)| Node.js

node oauth2驗證In my last articles, we looked at the implementation of the passport-local authentication strategy. We also looked at the various requirements to get started with the login form. 在上一篇文章中&#xff0c;我們介紹了護照本地身份驗證策略的實現…

vue2.0 引用qrcode.js實現獲取改變二維碼的樣式

vue代碼 <template><div class"qart"><div id"qrcode" ref"qrcode"></div><input type"text" id"getval" value"" placeholder"修改這個值改變二維碼"></div> <…

[轉載] Python列表排序 list.sort方法和內置函數sorted

參考鏈接&#xff1a; Python中的函數 Python列表排序 list.sort方法和內置函數sorted 很多時候我們獲取到一個列表后,這個列表并不滿足我們的需求,我們需要的是一個有特殊順序的列表. 這時候就可以使用list.sort方法和內置函數sorted,本文就是介紹list.sort方法和sorted內…

Java Thread類最終同步的void join(long time_in_ms)方法,帶有示例

線程類最終同步無效連接(long time_in_ms) (Thread Class final synchronized void join(long time_in_ms)) This method is available in package java.lang.Thread.join(long time_in_ms). 軟件包java.lang.Thread.join(long time_in_ms)中提供了此方法。 join(long time_in_…

RYU控制器安裝`

2019獨角獸企業重金招聘Python工程師標準>>> 同樣是參考了http://linton.tw/2014/02/11/note-how-to-set-up-ryu-controller-with-gui-component/的內容。 1. 由于Ubuntu中自帶有Python&#xff0c;因此直接開始安裝pip apt-get install python-pip apt-get i…

[轉載] mac開發者,你不得不知道的環境變更設置方法(如Java的環境變更 source命令 )

參考鏈接&#xff1a; 設置Java環境 Mac是基于Unix的&#xff0c;所有先來幾個常識與命令&#xff1a; Unix中雙引號單引號反引號(" )的區別 Unix中雙引號起到“弱引用”的作用:被引用的字符大部分被按照字符字面的意思解釋執行&#xff0c;除了了$,\,字符除外。 [因…

人形機器人正在美國史密森尼博物館中擔任導游的工作

Te article has been removed, please visit IncludeHelps home page for more articles 該文章已被刪除&#xff0c;請訪問IncludeHelp的主頁以獲取更多文章翻譯自: https://www.includehelp.com/News/a-humanoid-robot-is-doing-the-job-of-a-guide-in-the-smithsonian-museu…

normalizr API

APInormalizedenormalizeschemaArrayEntityObjectUnionValuesnormalize(data, schema)Normalizes input data per the schema definition provided. 根據提供的schema定義規范化輸入數據。data: required Input JSON (or plain JS object) data that needs normalization.schem…

[轉載] 【Java】基礎06:HelloWorld入門程序

參考鏈接&#xff1a; 從Hello World示例開始Java編程 HelloWorld它的中文意思是&#xff1a;“你好&#xff0c;世界”。 仿佛代表著計算機對世界說出來的第一句話&#xff0c;因為它簡潔實用&#xff0c;所以被作為入門程序廣泛使用。 Java程序開發三步驟&#xff1a;編…

[轉載] Java中的命名參數

參考鏈接&#xff1a; Java命名約定 創建具有許多參數的方法是一個主要的缺點。 每當需要創建這樣的方法時&#xff0c;就在空氣中聞一聞&#xff1a;這是代碼的味道。 強化單元測試&#xff0c;然后進行重構。 沒有借口&#xff0c;沒有屁股。 重構&#xff01; 使用構建器模…

[轉載] JVM(一):JVM體系結構詳解

參考鏈接&#xff1a; JVM如何工作–JVM體系結構 JVM簡介 JVM是Java程序得以運行的平臺&#xff0c;也是Java程序可以跨平臺的底層支撐&#xff0c;從整體上來看&#xff0c;JVM的主要功能可以分為加載和執行兩大塊。其中類加載器負責.class文件的尋址與加載&#xff0…

數據庫連接池的設計思路及java實現

2019獨角獸企業重金招聘Python工程師標準>>> connectionPool.DBConnectionManager [java] view plain copy package connectionPool; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; i…

[轉載] java虛擬機 jvm 出入java棧 棧空間內存分配

參考鏈接&#xff1a; Java虛擬機(JVM)堆棧區域 java棧空間是一塊線程私有的內存空間&#xff0c;java堆和程序數據密切相關&#xff0c;那么java棧就是和線程執行密切相關。線程最基本的執行行為就是函數的調用。每次函數調用其實是通過java棧傳遞數據的。 數據結構中的棧的…

SVN命令行更新代碼

命令列表 svn help查看幫助信息 Available subcommands: add auth blame (praise, annotate, ann) cat changeli…

[轉載] Java中Runtime的使用

參考鏈接&#xff1a; Java中的JVM的關閉掛鉤 1 JDK中Runtime的定義 http://blog.csdn.net/lysnow_oss/archive/2007/05/12/1606349.aspx <轉載> 那就首先說點Runtime類吧&#xff0c;他是一個與JVM運行時環境有關的類&#xff0c;這個類是Singleton的。我…

窄帶物聯網(NB-IoT)初步了解

哪有什么天生如此&#xff0c;只是我們天天堅持。既然總有人要贏的話&#xff0c;為什么不能是我呢&#xff1f;[TOC] 什么是NB-Iot? 基于蜂窩的窄帶物聯網&#xff08;Narrow Band Internet of Things, NB-IoT&#xff09;成為萬物互聯網絡的一個重要分支。NB-IoT構建于蜂窩網…

ai人工智能_人工智能能力問答中的人工智能不確定性

ai人工智能1) Which of the following is true with respect to uncertainty in AI systems? Uncertainty arises when we are not 100 percent confident in our decisionsWhenever uncertainty arises, there is needs to be an estimation taken for getting to any conclu…