Question:
2 dimensional arrays with strings on C?
Job Chua
2011-03-11 04:21:09 UTC
I know how to use 2 dimensional arrays with "int".
My question is, what if i use strings?

Correct me if im wrong, but strings in C are initialized like this "char sample[10]".
Meaning a string of 10 characters right?

On the other hand, the format for initializing 2 dimensional arrays on c looks like this
"int x [2][3]={{......},{......}}"

if i use the string together with the 2 dimensional array, how would the initialization look like?
like this? "char sample[10][2][3]={{...},{...}}"

But if i type it like that, it would turn into a three dimensional array right? help please :(
Three answers:
Ramandeep
2011-03-11 04:34:07 UTC
try the following code



#include

using namespace std;



int main()

{

char a[][4]={{"abc"},{"sdc"},{"gjc"}};

cout<
cout<
cout<
return 0;

}
anonymous
2016-11-16 17:43:19 UTC
You declare a 2-dimensional array, the place each and every component is a char! Thats why a[0][50] is a char and additionally you attempt to cram a char set in there! the reason of utilising 2nd array of chars is to have a set of strings a[0],a[a million],... are char gadgets or strings and a[0][50] is a 51th char in first string! a[0] = "hi adult adult males"; is authentic a[0][0] = 'h'; is authentic
anonymous
2011-03-11 04:35:52 UTC
char sample[10][2]

this is like 10 array which can store two characters.

like this

ab

bc

cd

de

ef

fg

..

if you want more


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...