Question:

So lets say I have a struct like this:

struct example_structure
{
int thing_one;
int thing_two;
};

I also have an empty array which I am trying to fill with these structs. I am trying to add them as follows, but it doesn't seem to be working:

array[i].thing_one = x;
array[i].thing_two = y;

Instead of this is there a way to declare a variable of type example_structure and then add that to the array?

Answer:

struct example_structure
{
int thing_one;
int thing_two;
} myarray[100];

And then you would access those array elements like any other array:

myarray[10].thing_one=123;
myarray[10].thing_two=456;

if that is what you are trying to achieve.

website:

http://stackoverflow.com/questions/29353253/adding-a-struct-into-an-array

Adding a struct into an array(stackoverflow)的更多相关文章

  1. Why is processing a sorted array faster than an unsorted array(Stackoverflow)

    What is Branch Prediction? Consider a railroad junction: Image by Mecanismo, via Wikimedia Commons. ...

  2. 1.线性表-Array

    fatal.h #include <stdio.h> #include <stdlib.h> #define Error( Str ) FatalError( Str ) #d ...

  3. 6-18 Two Stacks In One Array(20 分)

    Write routines to implement two stacks using only one array. Your stack routines should not declare ...

  4. c++ struct与class的差别

    从语法上,在C++中(仅仅讨论C++中).class和struct做类型定义时仅仅有两点差别: (一)默认继承权限. 假设不明白指定,来自class的继承依照private继承处理.来自struct的 ...

  5. go convert slice to struct

    Question: in golang how to convert slice to struct scene 1:use reflect convert slice to struct func ...

  6. [名词解释]Constant Amortized Time

    http://stackoverflow.com/questions/200384/constant-amortized-time 分摊常量时间: Amortised time explained i ...

  7. [HIve - LanguageManual] Hive Operators and User-Defined Functions (UDFs)

    Hive Operators and User-Defined Functions (UDFs) Hive Operators and User-Defined Functions (UDFs) Bu ...

  8. [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数

    Built-in Operators Relational Operators The following operators compare the passed operands and gene ...

  9. (zhuan) How to Train Neural Networks With Backpropagation

    this blog from: http://blog.demofox.org/2017/03/09/how-to-train-neural-networks-with-backpropagation ...

随机推荐

  1. 使用 IncrediBuild 提升 VisualStudio 编译速度

    我现在有一个 100M 的代码,需要快速去编译他,我寻找了很多方法,本文记录我找到的 IncrediBuild 用于提交编译速度. 如果一个项目存在很多不相互依赖的项目,那么使用 IncrediBui ...

  2. Math.round(),Math.ceil(),Math.floor()

    Math.round() :round周围,求一个附近的 整数 小数点后第一位 < 5 正数:Math.round(10.48)       //  10 负数:Math.round(-10.4 ...

  3. Behavior Tree 用 Lua 实现一个最简行为树

    local function Traverse(node, ...) local t = node.type if t == SELECTOR then , #node do if Traverse( ...

  4. Akka-Cluster(2)- distributed pub/sub mechanism 分布式发布/订阅机制

    上期我们介绍了cluster singleton,它的作用是保证在一个集群环境里永远会有唯一一个singleton实例存在.具体使用方式是在集群所有节点部署ClusterSingletonManage ...

  5. Eclipse 中 Debug 调试 java 代码一直报 Source not found

    今天使用eclipse的debug调试代码,一直没法正常调试,一按F6就提示Source not found 根据提示发现可能是另一个项目影响了,所以把另一个项目Close Project,这次直接t ...

  6. Android核心技术Intent和数据存储篇

    女孩:上海站到了? 男孩:嗯呢?走向世界~ 女孩:Intent核心技术和数据存储技术? 男孩:对,今日就讲这个~ Intent是各个组件之间用来进行通信的,Intent的翻译为"意图&quo ...

  7. 仿B站项目——(1)计划,前端工程

    计划 现打算: 计划用webpack打包 + 模板语言 + jquery + jquery ui + bootstrap做一个仿B站的静态网站. 网站兼容手机浏览器端. 部分模块打算仿照SPA用js加 ...

  8. Docker 与 虚拟机比较

    1, 更高效的利用系统资源2,更快速的启动时间3,一致的运行环境4,持续交付(Continuous Integration)和部署(Continuous Delivery) 5, 更轻松的迁移 6,更 ...

  9. tar与压缩详解

    .gz  gzip   gunzip(gzip -d) .zip .rar .bz2 gzip压缩文件不保留原文件 , 不能压缩目录 gzip   filename.x   用gzip压缩文件 gun ...

  10. ubuntu root默认密码(初始密码)

    ubuntu安装好后,root初始密码(默认密码)不知道,需要设置. 1.先用安装时候的用户登录进入系统 2.输入:sudo passwd  按回车 3.输入新密码,重复输入密码,最后提示passwd ...