pointers

    -5熱度

    2回答

    我直接放置代碼。 #include <stdio.h> struct A { int a; int b; }; int main() { struct A test; double *p = (double *)&(test.a); *p = 5; printf("variable a: %d\n", &test.a);

    1熱度

    2回答

    (從this deleted question改編。) 假設我們有一個數組int a[n],我們有在陣列的中間的指針元件(即int *p = &a[y],0 <和n-1)。 如果將p傳遞給我們沒有直接訪問數組的函數,那麼如何在給定數組元素的前後立即訪問這些元素,以便將它們添加到一起? 例如,如果a是在範圍之和可以很容易地這樣得到: int sum = a[y-1] + a[y+1]; 但是,在

    3熱度

    1回答

    之間有什麼區別:new int*[]和new (int*)[]: int** pA = new int*[2] // returns a pointer to an array of pointers to int. new (int*)[2] // what should this return ? Shouldn't it be same as the above. 同樣, float

    -2熱度

    2回答

    我爲char指針分配了一些空間,並嘗試訪問超出分配空間但仍然沒有分段錯誤。我的代碼如下: char *src = malloc(4); strcpy(src, "1234"); char *temp; for(int i = 0 ; i<5 ; i++) { temp = src; srC++; printf("ite ch %c

    0熱度

    3回答

    我有一個類的分配,我需要創建一個動態數組,存儲兩個指針,然後交換它們。 我差不多完成了,但由於某些原因,我無法將新的存儲值傳遞到數組中。我知道這個問題是最後兩行代碼,我知道這是錯誤的,但是我試圖修復它的代碼不會被編譯。 #include <iostream> using namespace std; // Function prototype void exchange(int*, int

    -3熱度

    2回答

    我是新來編程c。當運行下面的代碼,我收到以下錯誤與在=一個小箭頭指向登錄: 錯誤:不被忽略,因爲它空值應該是 * GCD = gcd_lcm((乘數1%乘數2 ),factor2,gcd,lcm); 我試圖按照向另一篇文章中找到的void類型返回值的步驟進行操作,但似乎無法在我的代碼中工作。有人可以幫我指出我的錯誤嗎?非常感謝。 #include <stdio.h> void gcd_lcm(

    3熱度

    4回答

    當我想要存儲字符串時,我不知道大小的方式是什麼。 我這樣做: #include <stdio.h> #include <conio.h> int main() { char * str; str = (char *)malloc(sizeof(char) + 1); str[1] = '\0'; int i = 0; int c = '\0

    1熱度

    1回答

    今天我收到了一個作業,約function pointer(binary tree)。 有代碼,我無法理解一大塊......我明白了一個function pointer是什麼以及它是如何工作的,但怎麼樣2 function pointers(1處於parameter) header.h typedef struct _node_ { int key; struct _node_ *left;

    -5熱度

    3回答

    指針變量保存的值只是需要爲下一個清除的內存位置的地址20個字節的數據。 我試過下面的代碼片段,但它清除指針值(開始內存位置的地址)的值。通過這樣做,我失去了內存位置的起始地址(指針值)。 srcadr = 0x105fc080; i = 20; *srcptr = &srcadr if(srcptr != NULL) { while (i < 20) {

    0熱度

    1回答

    class Base { int type; }; class Derived1 : public Base { ... }; class Derived2 : public Base { ... }; class Container { public: Derived1 f1; Derived2 f2; }; Container c; size_t off