Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
56 views

I mean that i is incremented by 1 right, then how does ptr + i equals ith block of memory since int size is 4? int i, n; printf("Enter the number of Integers: "); scanf("%d&...
0x0pralad0x0's user avatar
5 votes
5 answers
249 views

There are several source code files of a program. File file_a.c has an array in the global scope, and a function is provided that returns a pointer to its beginning: static int buffer[10]; int *...
Evgeny Ilyin's user avatar
-1 votes
2 answers
152 views

As far as I understand, pointer arithmetic is defined mainly in expr.add. But it seems defined only for static arrays, not dynamic ones: 4 When an expression J that has integral type is added to or ...
Oersted's user avatar
  • 3,732
1 vote
1 answer
183 views

Most low-level allocation functions return void *. If I want to perform pointer arithmetic on the obtained memory and/or allocate an array, is this the correct way to do it without invoking undefined ...
Oersted's user avatar
  • 3,732
1 vote
0 answers
90 views

I ran to an over-specialized container somewhere in production code. It was C++98 upgraded to C++11, but I wonder how many UBs (or implementation-defined behaviors) are in it. Basically, without any ...
Swift - Friday Pie's user avatar
2 votes
4 answers
302 views

I am currently learning about pointers in C programming as part of my training. I am particularly curious about using pointers directly within "for" loops. For example, in the following &...
Mehdi's user avatar
  • 21
3 votes
1 answer
173 views

Pointer arithmetic is only defined behavior for pointers to elements of the same array (or one past the array). Is there any defined behavior to get the distance in memory between two elements that ...
greenlagoon's user avatar
2 votes
1 answer
143 views

This is in one sense an extension to Is it UB to access a subobject by adding byte offset to the address of the enclosing object? under the assumption that P1839 is adopted. Consider the following ...
LtSten's user avatar
  • 175
1 vote
2 answers
156 views

A pointer of arrays is indexed once to get the array, then indexed again to get the element. This C-style trick should work with {$POINTERMATH ON}, but it definitely doesn't: {$POINTERMATH ON} ... ...
Zoltán Bíró's user avatar
1 vote
1 answer
83 views

#include <iostream> class ArrayClass { private: int *m_Arr; int i; public: int Size; ArrayClass() : Size(5), i(0), m_Arr(nullptr) { std::cout << "The ...
King Crows Schmétterling's user avatar
3 votes
4 answers
234 views

Take the following snippet: #include <stddef.h> _Bool foo(char * p) { return (p - 1) == NULL; } Both GCC and LLVM optimize the result to false. What in the standard allows the compilers to ...
Noah's user avatar
  • 1,759
1 vote
2 answers
124 views

I have seen that in the C++ abstract machines (if the are different), the mere act of forming a point to an invalid point in memory is undefined behavior. For example int* arr = new int[10]; int* last ...
alfC's user avatar
  • 16.8k
2 votes
1 answer
38 views

Initial pgm void assign( int **mat, int n, int m ) { int **p = mat; int **p_end = p + n; for ( ; p < p_end; ++p ) { int *q = *p; int *q_end = q + m; for ( ; q < q_end; ++q ) { printf( ...
hogar's user avatar
  • 33
1 vote
3 answers
215 views

In my C program book, I meet the question about (*p)[num2] there is a 2 dimension array named a[num1][num2] and a (*p)[num2] next,in the statement for(p=&a[0];p<&a[num1];p++) (*p)[i]=0; ...
阿卡丽's user avatar
1 vote
2 answers
378 views

We have a problem with a firmware project in 8051 assembly. It is used in an embedded system and now needs to be adapted to changes in the hardware. It contains a subroutine that sequentially reads ...
Daniel Jorge's user avatar
-1 votes
2 answers
186 views

I was looking for a way to find a given int in my array and i found this solution #include <algorithm> #include <iostream> using namespace std; int main() { int data[] = {23, 45, 56, 12,...
Pryhas's user avatar
  • 19
1 vote
2 answers
333 views

I don't understand how pointers works exactly in arrays. #include <stdio.h> int main() { int x[5] = {1, 2, 3, 4, 5}; int* ptr; // ptr is assigned the address of the third element ptr = ...
Jackob2001's user avatar
0 votes
4 answers
109 views

To learn more of C, I'm trying to recreate basic data structures. Here's a minimal example of my attempt at an array, which compiles and runs but has a problem detected by valgrind: #include <...
Roger Dodger's user avatar
0 votes
5 answers
138 views

Please can someone explain to me this strange pointer behaviour. Did I miss something?!? start first attempt int *foo=(int*)malloc(sizeof(int)*4);//allocates memory for 4 integer with size of sizeof(...
peks's user avatar
  • 27
-4 votes
1 answer
71 views

enter image description here Shouldn't the answer be 2nd ques? ptr1 saves the address of arr[0] and ptr2 saves the address of arr[3]. So (ptr2-ptr1) should be ((34(size of float)) -(04)) i.e., ...
Padmesh Sharma's user avatar
0 votes
3 answers
683 views

In C, I have three memory areas that are several hundred bytes long. I want to take the ith pair of 32 bits of the two memory areas, add them as two unsigned 32-bit integers, and store the result in ...
Kevin Stefanov's user avatar
4 votes
3 answers
411 views

XOR linked lists use pointer arithmetic in a way that looks suspicious to me given the changes in semantics introduced in C++17 (and discussed e.g. in Is a pointer with the right address and type ...
ByteEater's user avatar
  • 1,201
0 votes
2 answers
88 views

im trying to learn pointers and im confused in second line, can someone explain how it works? if we suppose 'a' base address is 100 int a[3][3] = {6, 2, 5, 0, 1, 3, 4, 9, 8}; printf("%p \n&...
Tolga's user avatar
  • 3
2 votes
4 answers
215 views

Recently I learned from user "chux" that it is legal to add 1 to an address that doesn't represent an array element. Specifically, the following provision in the standard (C17 draft, 6.5.6 ¶...
Lover of Structure's user avatar
0 votes
1 answer
64 views

Basically, I'm saving some coordinates in 2 arrays, arrayX and arrayY. Then, I want to change the value of a "blank" matrix in the coordinates that are saved in the previously mentioned ...
ATSlooking4things's user avatar

1
2 3 4 5
16