f



pointer to an array vs pointer to pointer

Consider the following program x.c:

#include <stdlib.h>
#include <stdio.h>

int main()
{
        int x[10];
        int **pp = &x;

        pp = NULL;  // just to get rid of compiler warning.

        return EXIT_SUCCESS;
}

When I compile this program under gcc 3.4.3 as
gcc -std=c99 -pedantic -Wall -Wextra x.c

it merely generates the warning
x.c: In function `main':
x.c:7: warning: initialization from incompatible pointer type

I thought the line
    int **pp = &x;
is in error because of different pointer types involved in the
assignment - '&x' is a pointer to an array and 'pp' is a pointer to
pointer.

So I do not understand why the compiler did not generate error for
this line.

Is this behaviour specific to the particular gcc implementation or the
ISO C99 Standard itself does not treat the above assignment as an
error ?

Please clarify.

Thanks
V.Subramanian
0
9/20/2011 12:14:09 PM
comp.lang.c 30656 articles. 5 followers. spinoza1111 (3246) is leader. Post Follow

5 Replies
737 Views

Similar Articles

[PageSpeed] 26

On 09/20/2011 08:14 AM, subramanian100in@yahoo.com, India wrote:
> Consider the following program x.c:
> 
> #include <stdlib.h>
> #include <stdio.h>
> 
> int main()
> {
>         int x[10];
>         int **pp = &x;
> 
>         pp = NULL;  // just to get rid of compiler warning.
> 
>         return EXIT_SUCCESS;
> }
> 
> When I compile this program under gcc 3.4.3 as
> gcc -std=c99 -pedantic -Wall -Wextra x.c
> 
> it merely generates the warning
> x.c: In function `main':
> x.c:7: warning: initialization from incompatible pointer type
> 
> I thought the line
>     int **pp = &x;
> is in error because of different pointer types involved in the
> assignment - '&x' is a pointer to an array and 'pp' is a pointer to
> pointer.
> 
> So I do not understand why the compiler did not generate error for
> this line.
> 
> Is this behaviour specific to the particular gcc implementation or the
> ISO C99 Standard itself does not treat the above assignment as an
> error ?

For initialization of a scalar object by a single expression, 6.7.8p11
says that "the same type constraints and conversions as for simple
assignment apply". 6.5.16.1p1 contains those constraints, listing the
permitted combinations of types for the left and right operands. Since
&x has the type int (*)[10], and p has the type int**, which are not
compatible types, none of those combinations apply. It is therefore a
constraint violation.

The standard makes no distinctions between "errors" and "warnings". It
only talks about diagnostic messages, a term which could cover either.
The standard requires that an implementation must generate at least one
diagnostic for any program that contains a syntax error or a constraint
violation. gcc met that requirement when it issued that warning.

Having generated the mandatory diagnostic, the implementation is free to
continue translating the program. The behavior of the resulting program,
if executed, is undefined.  I would guess that gcc probably translated
your code as if it contained an (int**) cast. There's only one feature a
C program can contain that requires the implementation to reject it: a
#error directive that survives conditional compilation.
-- 
James Kuyper
0
jameskuyper (5635)
9/20/2011 1:02:52 PM
> > I thought the line
> > =A0 =A0 int **pp =3D &x;
> > is in error because of different pointer types involved in the
> > assignment - '&x' is a pointer to an array and 'pp' is a pointer to
> > pointer.

I think the compiler generates an error if it cannot continue. Most of
the time if it sees something problematic it just warns and then
continues - it tells you there might be a problem with it and then
leaves it up to you to decide. You're the programmer after all - if
that's what you want it's not up to the compiler to actively stop you.

Which is why treating warnings as errors is probably a good plan in
many cases!

Conor.
0
9/20/2011 1:08:14 PM
On Tue, 20 Sep 2011 05:14:09 -0700, subramanian100in@yahoo.com, India
wrote:

> So I do not understand why the compiler did not generate error for
> this line.
> 
> Is this behaviour specific to the particular gcc implementation or the
> ISO C99 Standard itself does not treat the above assignment as an
> error ?

The ISO C standard doesn't say a great deal about dealing with errors.
Specifically:

       5.1.1.3  Diagnostics

       [#1]  A conforming implementation shall produce at least one
       diagnostic message (identified in an  implementation-defined
       manner)  if  a preprocessing translation unit or translation
       unit contains a violation of any syntax rule or  constraint,
       even  if  the  behavior  is  also  explicitly  specified  as
       undefined or  implementation-defined.   Diagnostic  messages
       need not be produced in other circumstances.7)

It doesn't make any distinction between errors or warnings, nor does it
require a diagnostic for each violation, nor does it prohibit the
implementation from issuing diagnostics for valid code (e.g. compilers
will often warn about possible mistakes, such as using an assignment
expression in the test of an if/while/etc, as it's often the case that the
programmer typed "=" when they meant "==").

Consequently, a compiler which simply printed e.g.:

	Note: the program may contain errors

for every file which it processed would conform to the requirements of the
standard. It issues the required diagnostic for code which contains
errors, and it issues a not-required-but-permitted diagnostic for code
which doesn't contain errors.


0
nobody (5159)
9/20/2011 1:19:02 PM
On Sep 20, 9:02=A0pm, James Kuyper <jameskuy...@verizon.net> wrote:
> On 09/20/2011 08:14 AM, subramanian10...@yahoo.com, India wrote:
>
>
>
>
>
>
>
>
>
> > Consider the following program x.c:
>
> > #include <stdlib.h>
> > #include <stdio.h>
>
> > int main()
> > {
> > =A0 =A0 =A0 =A0 int x[10];
> > =A0 =A0 =A0 =A0 int **pp =3D &x;
>
> > =A0 =A0 =A0 =A0 pp =3D NULL; =A0// just to get rid of compiler warning.
>
> > =A0 =A0 =A0 =A0 return EXIT_SUCCESS;
> > }
>
> > When I compile this program under gcc 3.4.3 as
> > gcc -std=3Dc99 -pedantic -Wall -Wextra x.c
>
> > it merely generates the warning
> > x.c: In function `main':
> > x.c:7: warning: initialization from incompatible pointer type
>
> > I thought the line
> > =A0 =A0 int **pp =3D &x;
> > is in error because of different pointer types involved in the
> > assignment - '&x' is a pointer to an array and 'pp' is a pointer to
> > pointer.
>
> > So I do not understand why the compiler did not generate error for
> > this line.
>
> > Is this behaviour specific to the particular gcc implementation or the
> > ISO C99 Standard itself does not treat the above assignment as an
> > error ?
>
> For initialization of a scalar object by a single expression, 6.7.8p11
> says that "the same type constraints and conversions as for simple
> assignment apply". 6.5.16.1p1 contains those constraints, listing the
> permitted combinations of types for the left and right operands. Since
> &x has the type int (*)[10], and p has the type int**, which are not
> compatible types, none of those combinations apply. It is therefore a
> constraint violation.

I am sorry, I couldn't understand why &x has the type int (*)[10],
other a pointer that points to a pointer that points to the initial
element of x.

section
6.3.2.1, paragraph 3:
---
Except when it is the operand of the sizeof operator or the unary &
operator, or is a
string literal used to initialize an array, an expression that has
type =91=91array of type=92=92 is
converted to an expression with type =91=91pointer to type=92=92 that point=
s
to the initial element of
the array object and is not an lvalue. If the array object has
register storage class, the
behavior is undefined.
---

So I think when we reference the array x, it decays to a pointer that
points to initial element of x, that is &x[0], and the line
       int **pp =3D &x;
is somewhat a pointer that points to a pointer that points to the
initial element of x. I think it is OK and why the compiler complains.
0
heconghui (48)
9/23/2011 9:20:48 AM
On 09/23/2011 05:20 AM, Stanley Rice wrote:
....
> I am sorry, I couldn't understand why &x has the type int (*)[10],
> other a pointer that points to a pointer that points to the initial
> element of x.
> 
> section
> 6.3.2.1, paragraph 3:
> ---
> Except when it is the operand of the sizeof operator or the unary &
> operator, or is a
> string literal used to initialize an array, an expression that has
> type ��array of type�� is
> converted to an expression with type ��pointer to type�� that points
> to the initial element of
> the array object and is not an lvalue. If the array object has
> register storage class, the
> behavior is undefined.
> ---
> 
> So I think when we reference the array x, it decays to a pointer that
> points to initial element of x,

Look again at the very beginning of that section: "Except when it is the
operand of ... the unary & operator ...". In the expression &x, the
array 'x' is the operand of the unary & operator. Therefore, this
expression is covered by that exception, and no such decay occurs.
-- 
James Kuyper
0
jameskuyper (5635)
9/23/2011 10:28:21 AM
Reply:

Similar Artilces:

pointers, pointers, pointers...
Hi There, I came up with following sample code to demonstrate my issue: #include <18F87K22.h> #device HIGH_INTS=TRUE, adc=16, ICD=TRUE #fuses NOWDT //No Watch Dog Timer #fuses WDT128 //Watch Dog Timer uses 1:128 #fuses HSM //Hi-Speed crystal oscillator #fuses NOBROWNOUT //No brownout reset #fuses NOPLLEN //No PLL enabled #fuses BBSIZ1K //1K words Boot Block size #fuses NOXINST //Extended set extension and Indexed typedef struct{ int8 foo, test; } TheStruct; TheStruct mystruct[5]; int16 myarr[2]; void Func(TheStruct *data, int16 *arr); void main (void) { myarr[0]=0xff; myarr[1]=0xaa; memset(&mystruct,0,sizeof(mystruct)); Func(myarr,&mystruct); while(true); } //------------------------------------------------------------------------------ void Func(TheStruct *strdat, int16 *arr) { strdat[0]->foo=(*arr[0]); strdat[0]->test=(*arr[1]); } This compiles just fine (CCS 4.119) but doesn't work, after the function, foo and test are still 0 cause myarr doesn't seem to be passed correctly to the function.... what am I doing wrong here? :( Thanks, Ron In <6549b0ed-900d-4279-b737-d8fa66831d94@r3g2000yqh.googlegroups.com> cerr <ron.eggler@gmail.com> writes: > TheStruct mystruct[5]; > int16 myarr[2]; > void Func(TheStruct *data, int16 *arr); > Func(myarr,&mystruct); Func is defined to...

pointer vs pointer to pointer
AIM: To write a queue with 3 operations. WHAT I GOT: It works PROBLEM: Have a question: Why do "pointer to pointer" in enqueue() and "a pointer" to deleteElement() both work fine ? Will enqueue() work fine if I pass just "a pointer" to it ? Will deleteElement() work fine if I pass "pointer to pointer" ? /* A queue implementataion with the operations that I need: * (1) Add element to the front of the queue * (2) remove an element with a unique ID (string constant) * (3) compare 2 elements (string comparison) * (4) print queue * * VERSION 0.1 */ #include <stdio.h> #include <stdlib.h> #include <string.h> enum { SIZE_ID = 100 }; struct myQ { char id[SIZE_ID+1]; struct myQ* next; }; struct myList { struct myQ* head; }; int enqueue(struct myList** s, const char* id); void deleteElement(struct myList* s, const char* id); int compareElements(struct myQ* e1, struct myQ* e2); void printQ(struct myList* s); int main(void) { struct myList* s = malloc(1 * (sizeof *s)); if(NULL == s) exit(EXIT_FAILURE); enqueue(&s, "1"); enqueue(&s, "2");enqueue(&s, "3"); printQ(s); deleteElement(s, "3"); printQ(s); deleteElement(s, "2"); printQ(s); deleteElement(s, "1"); printQ(s); free(s); return 0; } int enqueue(struct myList** s, const char* id) { ...

Pointer to pointer Vs References to Pointer
Q . When to use use pointer-to-pointer and reference-to-pointer to modify a pointer passed to a function ? According to me Which is better : double pointers OR Reference to Pointer ? There is no clear advantage and depends on programmer =91s choice or habit . As Nilesh mentioned =94 Reference to pointer=94 makes code easy But Pointer to pointer makes code easy to understand. So one can use any one . Why Pointer to Pointer is generally used ? 1. Pointer to pointer can be used in C and C++ but reference to pointer is limited to C++. a. Generally people start learning programming from C . So they get used to pointer to pointer. b.Pointer to Pointer usage makes project porting in C or C++ easy. 2. Generally libraries uses pointer to pointer approach like COM uses pointer to pointer for CoCreateInstance or QueryInterface. Fourm : Could you please let me know if these are the only reasons or i am missing something? Thanks Vikrant Example #include "stdafx.h" void Ref2Poi(int * &p) { *p =3D 10; } void Poi2Poi( int ** p) { **p =3D 10; } int _tmain(int argc, _TCHAR* argv[]) { int i =3D 13; int j =3D 14; int *p =3D &i; int *q =3D &j; Ref2Poi(p); Poi2Poi(&q); return 0; } "bansalvikrant@gmail.com" <bansalvikrant@gmail.com> writes: > Q . When to use use pointer-to-pointer and reference-to-pointer to > modify a pointer passed to a function ? &g...

Array of pointer Vs Pointer to Array
Hello, Is there any performance difference in using of the following two declaration? int (*ptr)[10]; //Array of 10 int pointers int *ptr[10]; // pointer-to-array of 10. Regards, Sangeetha. In article <4fde56d3.0410080658.4d3648bf@posting.google.com>, sangeetha <sangeetha_b@india.com> wrote: >Hello, > >Is there any performance difference in using of the following two declaration? Yes. One declares an array of pointers, one declares a pointer to an array. > int (*ptr)[10]; //Array of 10 int pointers Contrary to your comment, this declares ptr as a pointer to an ...

Once again pointer to first element vs pointer to array cast to pointer to element
I know that this topic has been discussed a lot, still I'd appreciate a clear cut (and correct) answer: I pass a multidimensional array to a function, which is defined as int f(int a[10][10]) { int *b=(void*)a; int *c=a[0]; /*...*/ } Now the questions come: - Is it guaranteed that b and c points to the same object (or is this implementation defined)? - Is it always true that a[1][1] refers to the same object as c[11] ? (There is no hole) - Does dereferencing b violate any aliasing rule? Thanks Szabolcs Szabolcs Borsanyi wrote: > I know that this topic has been discussed a lot, s...

Pointer-to-pointer-to-pointer question
The code example below shows the dynamic allocation of a 2D array. I must admit that it took quite a while for me to get there (I already have another posting to that effect), but I am glad that I finally got it working. Now here's the problem: I am able to get the 2D array dynamically allocated correctly as long as I am doing it "in-line" (i.e. without invoking any function). The moment I try to do it in another function, I get a core dump. Any help will be appreciated. Since this function is expected to update a pointer-to-pointer type, I am actually passing the pointer-to-pointer-to-pointer type to the function. What am I missing here? You can see that the source code works correctly when I am perform 2D array initialization "in-line" (i.e. by not invoking a function call) simply by un-commenting the line /* #define INLINE_INIT */ Masood /******************************************************/ #include <stdio.h> #include <stdlib.h> /*#define INLINE_INIT*/ #define MAXROWS 3 #define MAXCOLS 5 void buildTbl(int ***tblPtr, size_t numRows, size_t numCols) { *tblPtr = (int **)malloc(numRows*sizeof(int*)); /* C++ : *tblPtr = new (int*)[numRows]; */ for(size_t i = 0; i < numCols; i++) *tblPtr[i] = (int *)malloc(numCols*sizeof(int)); /* C++: *tblPtr[i] = new (int)[numCols]; */ } main() { int startVal = 5; int **tbl; #ifdef INLINE_INIT tbl = (int **)malloc(MAXROWS*sizeof(int*)); /* C++ : tbl = new (int*)[MAXROWS]; */ ...

pointer to pointer
Its just a very simple and basic program to learn exactly what is described in comments here. Can you provide a better (and short) exercise ? /* A program to learn how to use a pointer to a pointer. Here we take an array of char pointers. A char* in the array, of course, points * to some char. Array has only one element. We change the value of char pointed by array's element using a function. * * VERSION 0.0 */ #include <stdio.h> void replace_char_value(char* [], char); int main(void) { char* arrc[2] = {0}; char c = 'c'; arrc[0] = &c; printf("*arrc: %p, **arrc: %c\n", (void*)*arrc, **arrc); replace_char_value(arrc, 'w'); printf("*arrc: %p, **arrc: %c\n", (void*)*arrc, **arrc); return 0; } void replace_char_value(char* arr[], const char t) { **arr = t; } ==================== OUTPUT ======================= [arnuld@dune programs]$ gcc -ansi -pedantic -Wall -Wextra pointer-to- pointer.c [arnuld@dune programs]$ ./a.out *arrc: 0xbfffe8ab, **arrc: c *arrc: 0xbfffe8ab, **arrc: w [arnuld@dune programs]$ -- http://www.lispmachine.wordpress.com On 12/22/10 04:43 PM, arnuld wrote: > Its just a very simple and basic program to learn exactly what is > described in comments here. Can you provide a better (and short) > exercise ? Parse the arguments to a program. Don't forget argv is a pointer to pointer! Given ./a.out -a 10 -b ...

Pointers to pointers
How can you use a "pointer to a pointer" as a two dimensional array using 'new' and 'delete' rather than 'malloc' and 'free'? Thanks, Jonas Jonas Cord wrote: > How can you use a "pointer to a pointer" as a two dimensional array > using 'new' and 'delete' rather than 'malloc' and 'free'? Pretty much the same. int main() { int** data; data = new int*[100]; for (int i = 0; i < 100; ++i) data[i] = new int[100]; //use it for (int i = 0; i < 100; ++i) delete []...

pointers to pointers
Hi, i understood what pointers are and all stuff, and now i'm at the part with pointers to pointers and my book doesn't really help on this issue. let be: int a,*p,**q; how to make use of **q,*q and q ? Which who's address and/or who's value contains. I would like some examples like p=&a;// p contains the address of a and *p contains it's value but regarding **q,*q respectively q. Thanks. apropo wrote: > Hi, > i understood what pointers are and all stuff, and now i'm at the part > with pointers to pointers and my book doesn't really help on...

pointer to a pointer
My situation: I have a function that takes a pointer to an FSref as an argument. In the body of the function is a function call that also takes a pointer to an FSRef. I need to pass my original FSRef, but since I have only a pointer to it, I am assuming I need to dereference it twice when I call the second function. However, using something like &&myFSRef in the second function doesn't work. Can anyone tell me the proper way to do this? Thanks. In article <1105802448.cd52b3255e6c95476ce23f7be215a6a3@teranews>, Steven Daedelus <sdaedelus@ira.gov> w...

pointer to pointer
I have only used pointer to a pointer while manipulating arrays of arrays. I have not seen any C++ libraries that use pointer to a pointer as a function parameter. But I have seen it used in COM. If we want the function to create a new object and allow the passed in pointer to point to the object created we can pass a pointer to the reference. Is there anything special about COM that it needs pointer to a pointer. Is this becuase that COM can be used from C as well and we don't have references in C. In what other circumstances pointer to pointer can be used. Why don't we never see poi...

pointer of pointer
Hi I have a structure, B_t is another structure typedef struct{ int len; unsigned char code[12]; B_t *b; }A_t Now I need to pass A_t into a function to evaluate I use pointer of pointer void evaluate(A_t **a) My question is how to evaluate the component of this structure (*a)->b??? seems not right Thanks a lot! <qianz99@gmail.com> wrote in message news:1178915812.306611.242380@y80g2000hsf.googlegroups.com... > Hi > > I have a structure, B_t is another structure > > typedef struct{ > int len; > unsigned char code[12]; > B_t *b; > }A_t > > Now I need to pass A_t into a function to evaluate > I use pointer of pointer > > void evaluate(A_t **a) > > My question is how to evaluate the component of this structure > > (*a)->b??? > > seems not right > It is right. It is ugly and so you might be better off with A_t *aptr; aptr = *a; aptr->b; Code that a machine can read correctly isn't necessarily easy for humans to read. The extra variable will almost certainly be optimised away by the compiler, so there is unlikely to be any efficiency penalty. -- Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm On May 11, 1:36 pm, qian...@gmail.com wrote: > My question is how to evaluate the component of this structure > > (*a)->b??? > It accesses member b of A_t, which a pointer to B_t. Whether it is right or not depends upon what you mean by 'eva...

Pointer to Pointer or not?
Hi I am creating my own Queue class to learn about Queues and pointers. I have come across a question of two styles and I don't know if there are any dangers associated with them. I coded my remove function as follows template <class T> bool adsQ<T>::Remove(T* theData) { Qnode<T>* removeNode = 0; if (true == isEmpty()) { //cout << "False" << endl; return false; } else { /* What I am trying to achive here is to change the data pointed to by theData to the data pointed to by pData.*/ *theData =*(pHead->pData); //Data exchan...

Pointers for these pointers...?
Hi Everyone: I'm trying to develop a property list to include as metadata about my object classes. i.e. I want each class I'm developing to include a PropertyList which will contain ObjectProperty pointers. ObjectProperty is a class containing the typeid.name() of a type as it's ObjectType as well as an ObjectName and ObjectDescription. Basically 3 strings of metadata describing each of a class' member variables (and hopefully functions) so that the class can report to a query from another class what properties it has available for access at run time. Here is what I have and t...

c++: pointers to pointers
Hi, I have an array of pointers defined as such: myArray** ptr = new myArray[10]; for some reason i get a compile time error stating there is no default constructor for myArray. The problem is that i should not need to define one since myArray is a pointer to a pointer and so should not have a default constructor - its a primitive data type and not an object. Any help appreciated. Regards, A A wrote in news:3f9e5e27_1@news.iprimus.com.au: > Hi, > > I have an array of pointers defined as such: > > myArray** ptr = new myArray[10]; myArray** ptr = new myArray *[10]; &g...

pointers and array of pointers
Hi, Like almost all of beginners I have problem understanding pointers. Please, look at this piece of code, and please explain me why myswap function doesn't work as it's supposed to do, whereas myswap2 is doing exactly what I want it to do - swaping pointers. Where I made a mistake? Thanks void myswap(char *pa, char *pb){ char *tmp; tmp=pa; pa=pb; pb=tmp; } void myswap2(char *sw[]){ char *tmp; tmp=sw[0]; sw[0]=sw[1]; sw[1]=tmp; } int main(void){ char *a="1111", *b="2222", *A[]={"1111","2222"}; printf("1: %s, 2: %s\n", a,...

pointer to an array of pointers
Hi, Could anyone please tell me how to dereference a pointer to an array of pointers? Regards On Dec 3, 7:13 pm, ramu <ramu....@gmail.com> wrote: > Hi, > Could anyone please tell me how to dereference a pointer to an > array of pointers? > > Regards *p or p[0]. A pointer to an array of N pointers is char *(*)[N]. Example: char *(*foo)[N] = NULL; "ramu" <ramu.ask@gmail.com> wrote in message news:f0977e82-d97d-4124-8f94-f3addd5b6c8a@s8g2000prg.googlegroups.com... > Hi, > Could anyone please tell me how to dereference a pointer to ...

Pointer to array of array of const pointer
In order to let compiler catches unintended changes of a passed object in a function, we added const, for example: struct MyStruct { int Value; }; void bar(const MyStruct * const pObj) { // pObj = <address of another MyStruct object>; // pObj->Value = <some value>; } int main() { MyStruct AObj; bar(&AObj); } If uncommented the two lines in bar(), the compiler should be able to catch them. This also works for array of (const) pointers (to const): void foo(MyStruct const *const (PtrAry)[10])...

Struct pointer vs. struct array pointer
Say I'm using a standard windows RECT structure... RECT *prect; // I can write prect->left = 0; // but I can also write prect[-1].left = 0; prect[0].left = 0; prect[1].left = 0; and the compiler won't complain... So, what did I define in the first line, a pointer to ONE structure or a pointer to an ARRAY of structures? How can I define a pointer to an array? I don't know in advance how many RECTs there will be in the array. I'm asking because I can't make WinDbg (nor MSVC debuffer) to show me the whole array of RECTs. Thanks On Wednesday, February 20, 2013 9:17:32 AM UTC, aleksa wrote: > Say I'm using a standard windows RECT structure... > > > > RECT *prect; > > > prect->left = 0; > As the code stands, prect is set to whatever random data was in the memory space assigned to it. So the second line sets a random memory location to zero. Usually the result will be a segmentation fault, but not always. To fix this problem RECT rect; prect = &rect; but of course this us useless. Why not just write rect.left = 0 instead? > > How can I define a pointer to an array? > > I don't know in advance how many RECTs there will be in the array. > > It bcoomes useful here RECT rectarray[15]; rectarray, is to all intents and purposes, a constant pointer to a block of 15 RECTs. So what if you don't know how many you'll need at...

multidimensional array = pointer to pointer ?
I've read the FAQ and several posts on multidimensional arrays and how their names decay to pointer to arrays (not pointer to pointers). If this is so, why does the following code fragment compiler and run correctly?: #include <stdio.h> int main() { int example[4][4]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; printf("\nBEFORE DOUBLE DEREFERENCING of example:\n"); printf("\nexample[0][0] = %d\n",example[0][0]); **example = 100; /* double dereferencing 'example' */ printf("\nAFTERDOUBLE DEREFERENCING of example:\n\n\n"); pri...

C++ Exception: Why does this program behave differently for pointer and array of pointer
Hi, can somebody please help me figure out what is wrong with the following program? If I run this program, then the destructor for the first pointer in the array is called because exception occurs as soon as it tries to allocate the second pointer in the array but the destructor for the pointers a1 and a2 are not called. Does any one have answers ? Thanks in advance, Divick #include <exception> #include <iostream> using namespace std; class A { static int count; int id; public: A() throw(int) { id = c...

Pointer-to-array issues in C vs C++
About 20 days ago, "John Harrison" <john_andronicus@hotmail.com> replied to a message which I had written: > > > Q1 . What is the use of pointer to an array? > > > > It points to it. (The name of an array is also a pointer to it.) > > No, the name of an array decays to a pointer to the first element of the > array. A pointer to an array and a pointer to the first element of an array > are not the same thing. > > int a[10]; > cout << &a + 1 << endl; > cout << a + 1 << endl; > > The two statements pr...

Cast a pointer to array to base class pointer to array
Hi, A have a pointer to an array of a derived class, which I want to cast to its base class. That is, im trying to do something like this: void f( derivedClass* derivedData[] ) { baseClass* data[] = dynamic_cast<baseClass*[]>(derivedData); } This can't compile, so I'm wondering how to make it work? Best Regards Hansen Hansen wrote: > Hi, > > A have a pointer to an array of a derived class, which I want to cast to > its base class. That is, im trying to do something like this: > void f( derivedClass* derivedData[] ) > { >...

pointers to pointers question
How come something like: #include <stdio.h> int main(int argc, char **argv) { char **arg; int i; for ( i = 0; argv[i] != NULL; ++i ) { puts(argv[i]); } for ( arg = argv; *arg != NULL; ++arg ) { puts(*arg); } return 0; } doesn't require a explicit & before argv in the for loop, but something like #include <stdio.h> #include <stdlib.h> int main(void) { char *ptr = "Garbage"; char **pptr; pptr = &ptr; printf("The value is: % s\n", *pptr); } does require an explict & Chad Chad w...

Web resources about - pointer to an array vs pointer to pointer - comp.lang.c

Plaxton Pointer - Wikipedia, the free encyclopedia
The Plaxton Pointer (originally known as the Reeve Burgess Pointer , and later as the TransBus Pointer and Alexander Dennis Pointer ) is a successful ...

Michael Pointer (@michaelpointer) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Thread: I'm looking for pointers to a Google Maps API overview.
... outline for a map, making it super-easy to edit, and also to have it in the most convenient form for someone browsing over the data. Any pointers ...

Pointer for iPhone, iPad, and iPod touch on the iTunes App Store
Get Pointer on the App Store. See screenshots and ratings, and read customer reviews.

Kobe Bryant 45 Points (NBA Record 12 Three-Pointers) vs Seattle Super Sonics - Highlights 07/01/2003 ...
Los Angeles Lakers vs Seattle Super Sonics 07/01/2003 Ignore Tags : mix derrick rose mix miami heat new york knicks mix thunder lebron james ...

Shark warning as white pointers cruise off Perth beaches
Large schools of salmon are bringing danger to Perth's beaches and waters as Great White Sharks follow the fish along the coast.

Footy kicks logic for a nine-pointer
Apart from hilarious change strips, footy’s number one growth industry appears to be inexplicable phenomena

Inside Mail: All the big bets, market movers, work whispers, trial pointers and quaddies for Canterbury ...
ALL the big bets, market movers, work whispers, trial pointers and quaddie tips for Canterbury and analysis of the Group 1s at Flemington on ...

Perth fisherman captures chilling footage of white pointer shark
... joked “the fish became the fisherman” after a close encounter with a shark. Mark Peacock captured chilling footage of the white pointer ramming ...

Canterbury Bulldogs coach Des Hasler calls victory over Melbourne Storm a four-pointer
Bulldogs coach Des Hasler described the victory over the Storm in Melbourne as a "four-point" win.

Resources last updated: 3/24/2016 4:29:09 PM