本文介绍了为什么多维数组,而不是一维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现在C简单的划词搜索。我试图存储在一维阵列然而正在给出错误的单词列表。我尝试了数组设置为2维和数组似乎消失。有人可以解释这个给我好吗?

 字符字[10] [10] = {狗,猫,马,牛,羊,猴,大象, 乌鸦,鱼,蛇};//此处错误
CHAR字[10] = {狗,猫,马,牛,羊,猴,大象,乌鸦,鱼,蛇};


解决方案

 字符字[10]

将让你的记忆连续10块,即可以在一个字符串存储与10其中最大长度为

 字符字[10] [10]

将让你的内存10X10块。因此您可存储10个字符,10串每

I am implementing a simple word search program in c. I tried storing the list of words in a single dimensional array however an error was being given. I tried setting the array to 2-dimensional and the array seemed to go away. Can someone explain this to me please?

char words[10][10] = {"dog", "cat", "horse", "cow", "goat", "monkey", "elephant", "crow", "fish", "snake"};

//error here
char words[10] = {"dog", "cat", "horse", "cow", "goat", "monkey", "elephant", "crow", "fish", "snake"};
解决方案
char words[10]

will get you 10 continous blocks of memory, i.e you can store a single string with a max length of 10 where as

char words[10][10]

will get you 10X10 blocks of memory. so you can store 10 strings of 10 characters each.

这篇关于为什么多维数组,而不是一维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:10