1

I have an array of ints, denoted as int* myInts[100];

When I try to print the 0th index like so,

printf("%d\n",myInts[0]);

I get the following compiler warning:

warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]

Why is this?

3 Answers 3

4

If you want an int array, declare it as

int myInts[100];

If you want array of int *, print it as

printf("%p\n", (void *)myInts[0]);
Sign up to request clarification or add additional context in comments.

3 Comments

int * means pointer to int and [100] means array of size 100. Collectively an array of size 100 containing int pointers.
how would I initialize all of the indexes in the array to 0?
int myInts[100] = {0};
1
int* myInts[100];

declares an array of one hundred pointers to integers, not one hundred integers as you describe.

You need to use:

int myInts[100];

instead.

Comments

1

int* myInts[100]; It means array of 100 integer pointer. int myInts[100]; It means array of 100 integer.

to eliminate warning do like printf("%p\n", (void *)myInts[0]);

1 Comment

you should remove the * in the second declaration to match the text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.