C/C++:

#include "stdio.h"
struct People
{
    int age;
    int arr[3];
};

void main()
{
    //printf("%d\n",sizeof(People));
    struct People m={3,{4,5,6}};
    struct People m2=m;
    m2.arr[2]=99;
    printf("%d\n",m.arr[2]);
}

C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 结构
{
    class Program
    {
        static void Main(string[] args)
        {
            A a;
            a.age = 111;
            a.arr = new int[] { 11, 22, 33 };
            A a2 = a;
            a2.age = 99;
            a2.arr[0] = 66;
            B b = new B();
            b.age = 111;
            b.arr = new int[] { 11, 22, 33 };
            B b2 = b;
            b2.age = 99;
            b2.arr[0] = 66;
            Console.WriteLine(a.age);
            Console.WriteLine(b.age);
            Console.WriteLine("-----------------------------------------------------------------------------");
            Console.WriteLine(a.arr[0]);
            Console.WriteLine(b.arr[0]);
        }
    }
    struct A
    {
        public int age;
        public int[] arr;
    }

    class B
    {
        public int age;
        public int[] arr;
    }
}

 

相关文章:

  • 2021-10-25
  • 2022-02-07
  • 2022-01-30
  • 2022-01-01
  • 2022-01-06
猜你喜欢
  • 2022-12-23
  • 2021-08-24
  • 2021-12-02
  • 2021-08-18
  • 2022-12-23
  • 2021-11-08
相关资源
相似解决方案