Archived

This topic is now archived and is closed to further replies.

tonymontana

POÝNTERSSSSS

Recommended Posts

#include <iostream> using namespace std; const int MAX=20; void Showadress(int*,int); int main() { int* tdizi[MAX]; Showadress(tdizi,MAX); // FİRST QUESTİON return 0; } void Showadress(int* dizi,int r) { for(int cntr1=0; cntr1[edited by - tonymontana on January 18, 2004 7:45:41 AM]

Share this post


Link to post
Share on other sites
Declaring dizi as int** dizi and removing the & in your loop should fix things. The reasons can be found in the following answers.

1) tdizi is an array of int*. tdizi is therefore of type int*[MAX], which will decay to int**, not to int*

2) dizi is a variable (in technical terms, it''s an lvalue), and therefore has an address. cntr1 is a variable, and therefore has an address ... but (dizi+cntr1) is not a variable (in technical terms, it''s an rvalue) and therefore doesn''t have an address.
&dizi+cntr1 will take the address of dizi (which is a local variable and NOT tdizi!) and increment it by cntr1.
&(dizi+cntr1) tries to take the address of the ''temporary variable'' that would hold the rsult of dizi+cntr1... which obviously must fail.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites
Your declaring your array as an array of int pointers, because arrays and pointers are related the first element is always a pointer to the next element in the array but because you are declaring the array to be an array of pointers an extra level of indirection is introduced.

Share this post


Link to post
Share on other sites