pointer-arithmetic

    5热度

    2回答

    现在我们知道做出界限指针算术具有未定义的行为,如SO question中所述。 我的问题是:我们可以解决这种限制吗?通过转换为std :: uintptr_t进行算术运算然后转回指针?是保证工作吗? 例如: char a[5]; auto u = reinterpret_cast<std::uintptr_t>(a) - 1; auto p = reinterpret_cast<char*>(

    2热度

    4回答

    我是编程和学习数组中指针的新手。我现在有点困惑。看看下面的程序: #include <stdio.h> int fun(); int main() { int num[3][3]={23,32,478,55,0,56,25,13, 80}; printf("%d\n",*(*(num+0)+1)); fun(num); printf("%d\n", *

    0热度

    4回答

    指针运算这是我的第一个问题:) double MyArray[][6]; double* Myptr = MyArray[0]; 所以我一直在想,为什么在指针运算,我可以谱写指针在这样的单一维度移动, *(Myptr + i); ,但如果我试图通过使用for循环数组的尺寸来移动它不会让我 *(*(Myptr + i) + j); 但它确实让我使用这个表示法与数组本身。 *(*(MyA

    -2热度

    4回答

    #include <stdio.h> #include <string.h> int main() { char str_a[20]; char *pointer; char *pointer2; strcpy(str_a, "Hello, world!\n"); pointer = str_a; printf(pointer); pointer2 = pointer + 2;

    1热度

    1回答

    指针是如何按其类型递增的。 例如,如果我们有 int *ptr; ptr++; //would point to the next integer i.e. it would increment ptr by 4bytes in 32 bit system 我想知道这是怎么在内部完成。

    3热度

    2回答

    用C所以学习指针和我认为,作为一个练习,我可以做一些普通的数组,我得到了使用void当**它的工作是这样的: struct array{ void **data; size_t size, capacity; }; 这样插入元素: void array_append(array *a, void *element){ if(a->size == a->capac

    1热度

    5回答

    这是我的代码,工程。该函数初始化数组,一个以值0 - 3 int main(void) { int a[4]; pointer(a); return 0; } void pointer(int* a) { int *p, i; p = a; for(i = 0; i < 4; i++) { *a++

    3热度

    3回答

    我想将指针向前移动一个字节。 但我得到这个错误: lvalue required as increment operand 有了这个代码: int **test = 0; ((char *) *test)++; 但它是罚款与此: int **test = 0; char **t2 = (char **) test; (*t2)++; 我该怎么做后者简洁?

    9热度

    2回答

    我写和从存储器映射寄存器读取,像这样使用“无效*”的指针: //READ return *((volatile uint32_t *) (map + offset)); //WRITE *((volatile uint32_t *) (map + offset)) = value; 但是编译器给了我这样的警告: warning: pointer of type ‘void *’ use

    2热度

    3回答

    在下面的程序中,这里ptr已被声明为指向整型指针的指针,并且指定了数组p[]的基址,该数组已被声明为整型指针数组。假设ptr包含地址9016(假设p的起始地址是9016),在ptr递增之前和ptr++之后,它将包含值9020(假设int需要4个字节)。 所以ptr-p应该给出输出为4即(9020-9016 = 4)。但它将输出结果设为1。为什么? #include<stdio.h> int ma