小编Fai*_*han的帖子

C++ Memory Address

Please excuse me if this is a repeated question

This is my code

#include "stdafx.h"
#include <stdio.h>
#include "iostream"
#include <stdlib.h>
using namespace std;

int main()
{
    char * name = "Hello";

    cout << "2" << endl;
    cout << "Address2 is " << &name <<  "   value at address is " << * (&name) << endl;
    cout << "Next address2 is " << &name + 1 << "   value at address is " << name + 1 << "  " …
Run Code Online (Sandbox Code Playgroud)

c++ memory

6
推荐指数
4
解决办法
162
查看次数

C ++内存地址分配

道歉,我感到沮丧,并在没有适当详细信息的情况下通过手机发布了问题

考虑以下C ++代码:

 int arr[2];
    arr[0] = 10;
    arr[1] = 20;
   // cout << &arr;
    for (int i = 0; i < 2; i++)
    {
       cout << &arr + i << "\t\t"<<endl;
    }

    cout << sizeof (arr);
Run Code Online (Sandbox Code Playgroud)

cout进入for循环打印

0x7ffeefbff580 0x7ffeefbff588

比第一个元素多8个字节

我的问题是,如果在我的机器上sizeof(int)是4,为什么还要再增加8个字节而不是4个字节?

c++ memory

0
推荐指数
1
解决办法
85
查看次数

标签 统计

c++ ×2

memory ×2