I am writing a c++ code for displaying a 3D cube.
I have some small problems with arrays.

I want to initialize just some interval of array.


int array[10][10]=0;

//now I want to initialize just an interval

array[0][5] TO array[0][8]=1;


I know that in place where the word TO is, has do be
some sign, which will do initialization from one place
of array TO another, but I don't know which.

Maybe this is not correct procedure so fell free to tell
me a better solution.

Thanks for help!


7 Years
Discussion Span
Last Post by firstPerson

Whenever you initialise an array partially,the un-initialised part of the array are initialised to zero's automatically.Thats the only thing which happens and as per my knowledge there is no such symbol which would function as you suggested.

For it there are two ways, one is you initialising every block value by entry using some looping construct, another is as shown below :

int array[5][5]={ {0,0,0,0,0},
                            {4,4,4,4,4} };
// or as
int array[5][5]={ 0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4 };

To my knowledge you can't initialize just a portion of the elements in an array, it's all or none. You can use a loop to assign a desired value to a portion of an array. That's what I would encourage you to do.


what is array of pointer

It literally means what it is named... Its an array of pointers.

You know this is possible right ???

char *p="Hello";

Here it is a character pointer pointing to a string.

Same way this is also possible:

char *arr[4]={"Hello ","I ","am ","xyz."};

Here you have an array arr which is a collection of char * type pointers.So its an array of pointers.


what is array of pointer

Well a pointer is an array in some way, so you can think of it as
a array of arrays, or a 2d array.

//Both Similar
char *A[2] = { "hello", "world" };
char B[10][10] = { "hello", "world" };

They are both similar in some ways. Although you should be careful
when using either or.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.