Questions on Pointers

I have two questions.

Question 1
==========

if we say static int i; the variable i is initialized to 0 by default.

1
2
3
4
static int **a;
a = new int*[5];
for(int i=0;i<5;i++)
  a[i] = new int[5]


but with the above code, the array values are not initialized to 0. So if we wish to initialize to zero, will we be able to do it? and how?

Question 2
==========

lets consider char* c="Some Char". Here c is pointing to an array of characters. same why why is that we are not able to make int* i point to an arbitrary number of integers??


Last edited on
why is that we are not able to make int* i point to an arbitrary number of integers??
Huh? Then what did you do on line 2 before?
Yeah.. I just realized how dumb my 2nd question was...!!!

Sorry abt that... Can you let me know the answer for question 1?
U can use loops or you can declare static int a[5][5] if you already know its size. Its good practice to initialise static variable even though with a standard compiler it is initialized by definition.
The answer is that you can:
int n[] = {1, 2, 3, 4};
Being of an array type, n is really a pointer to the array of integers. Exact same thing as your char* example
Oh! I just realized.
Don't make static pointers to dynamic memory. You'll never be able to free it unless you know when will be the last function call.
Topic archived. No new replies allowed.