मेरे पास एक उदाहरण है जिसमें 2 डी सरणी के लिए पॉइंटर शामिल है। क्या कोई इस बात में मेरी मदद कर सकता है कि इस उदाहरण में क्या चल रहा है?सी में 2 डी सरणी और सूचक - तत्वों का उपयोग कैसे करें?
int main()
{
int i = 0, j=0, sum0=0, sum1=0;
int data[4][3] = { {23,55,50},{45,38,55},{70,43,45},{34,46,60}};
int *Ptr;
Ptr = *data; //Why is the indirection operator used here?
// Does Ptr = 23 by this assignment?
for (i=0; i<4; i++) {
sum1 = 0;
for (j = 0; j < 3; j++) {
sum1 += data[i][j];
}
if (sum1 > sum0) {
sum0 = sum1;
Ptr = *(data + i); // Seems like this statement makes Ptr
} // point one row below ... what syntax
} // can you use to access columns then?
// Is it possible to use pointer arithmetic
for (i=0; i<3; i++) // to access elements of data[i][j] that
printf("%d\n", Ptr[i]); // are not at j = 0?
return 0;
}
क्या यह [टैग: होमवर्क] है? – Alexander
यूप! मैं एक परिचय सीएस कोर्स ले रहा था और यह सिर्फ मेरे व्याख्यान नोट्स से दिया गया एक उदाहरण था। – shafools