POÝNTERSSSSS

Started by
2 comments, last by tonymontana 20 years, 3 months ago
#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]
Essegin Ziki:) bunu bu sitede imza hesabına yazsam kimse anlamaz!!!:)
Advertisement
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)
"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
sorry but i didn''t understand
may anyone explain simply??
Essegin Ziki:) bunu bu sitede imza hesabına yazsam kimse anlamaz!!!:)
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.

This topic is closed to new replies.

Advertisement