please tell me the answer of this question.it is irritating me a lot. i have searched many books but not getting it.please help!!

Recommended Answers

All 11 Replies

Is that the exact question you have, or are you paraphrasing it into incoherence?

An array is just a pointer. The only difference is that arrays always point to the same memory and will have a static number of elements.

int main(int argc, char** argv)
{
    int* ptr;      //A pointer to an int.
    int array[4] = {2, 4, 6, 8};  //A static array.
    int fifi = 20; //A regular integer.

    ptr = &fifi; //Makes ptr point at fifi.
    printf("%i\n", *ptr);   //This will printf the value of fifi, perfectly legal.
    printf("%i\n", ptr[0]); //This is also legal, does the same thing, but counterintuitive.
    ptr = &array[1]; //You can make them point to the middle of an array.
                     //This effectively makes ptr be a 3-element array with the values
                     //4, 6, and 8.
    printf("%i\n", ptr[2]); //This should print the 8 located at array[3].
    array = &fifi;    //THIS, HOWEVER, IS ILLEGAL C. ARRAYS CANNOT BE MOVED.
    return 0;
}

Also, notice how some people use "char* argv[]" and others use "char** argv"? They're both the same thing for that very reason.

An array is just a pointer.

Wrong. An array name when used in value context is converted to a pointer to the first element. But an array is not a pointer, which is easily proven by switching to an object context:

#include <stdio.h>

int main(void)
{
    int a[] = {1,2,3,4,5};
    int *p = &a[0];

    printf("%zd\n%zd\n", sizeof a, sizeof p);

    return 0;
}

Also, notice how some people use "char* argv[]" and others use "char** argv"? They're both the same thing for that very reason.

It's a shame that this notation was allowed, because it's both the source of and continued cause for confusion about pointers and arrays. Also note that it's only allowed on the first dimension of an array. void foo(int a[][10]) is not equivalent to void foo(int **p) .

When you're talking about runtime, a computer honestly can't tell the difference and most of these differences between arrays and pointers are resolved during compile. sizeof() just happens to be one of those static expressions that gets resolved in such a way. The wording of my answer had to do with "abstract representation" in the OP's title.

When you're talking about runtime

I'm talking about the conceptual difference, not runtime or compile time. Is that "abstract" enough for you?

The wording of my answer had to do with "abstract representation" in the OP's title.

So calling a blatantly incorrect explanation "abstract" suddenly makes it correct? Who knew? :icon_rolleyes: Maybe you should wait until the OP clarifies the question before trying to answer.

what is happening hereby? :-o why all are in dispute even after that i m not getting what are you saying ??

i m not getting what are you saying ??

Let's start over then. Your original question made no sense. Please clarify what you mean by "abstract level representation".

Let's start over then. Your original question made no sense. Please clarify what you mean by "abstract level representation".

after the day when i post that question,i have DS exam.that question came in that even.here goes that question. i m writing it exactly as it comes in my exam.
GIVE AN ABSTRACT LEVEL REPRESENTATION OF THE DATA STRUCTURE ARRAY ?

this is copied from my question paper.

Arrays are typically viewed as so intrinsic that they're not often treated as a separate data structure. But you can certainly create an abstract data type based on at least the essential properties of the array (C++'s vector class is one such example).

Unfortunately, the question is still somewhat ambiguous. Can you give an example of an "abstract level representation" of one of the other data structures you've learned?

A contiguous sequence of memory?

A contiguous sequence of memory?

in that answer. it is given like post conditions, pre conditions, and restriction on data which we can enter in array. means it like that they are defining array that how it will work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.