複習指標陣列以及如何把二維陣列賦值給二維指標
阿新 • • 發佈:2018-12-30
#include <cstddef> #include <iostream> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; void listadd(){ int flag = 0; ListNode* pre = new ListNode(0); ListNode* l1 = new ListNode(1); l1->next = new ListNode(2); ListNode* l2 = new ListNode(1); l2->next = new ListNode(2); ListNode* l3; l3 = pre; while (l1 != NULL || l2 != NULL){ int val1 = 0; if (l1 != NULL){ val1 = l1->val; l1 = l1->next; } int val2 = 0; if (l2 != NULL){ val2 = l2->val; l2 = l2->next; } int temp = 0; temp = val1 + val2 + flag; l3->next = new ListNode(temp % 10); flag = temp / 10; l3 = l3->next; } if (flag == 1){ l3->next = new ListNode(1); } } float *find(float(*pionter)[4], int n); int main(){ int iArr[2][3] = { 0, 1, 2, 3, 4, 5 }; int* p = iArr[0]; int(*pArr)[3] = iArr; //如何把一個二維陣列賦值給二維指標,[3]是寫死的規定。 呼叫這個變數和定義這個變數含義不同,C語言缺點,不能返回陣列。 int a = *(*(pArr + 1) + 2); int b = *(*(iArr + 1) + 2); return 0; }