Skip to main content
1823 votes
20 answers
136k views

As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Joel says that it's because of pointer ...
Dinah's user avatar
  • 54.3k
254 votes
10 answers
190k views

When a pointer to a particular type (say int, char, float, ..) is incremented, its value is increased by the size of that data type. If a void pointer which points to data of size x is incremented, ...
Siva Sankaran's user avatar
136 votes
5 answers
382k views

Let us assume, int *p; int a = 100; p = &a; What will the following code actually do and how? p++; ++p; ++*p; ++(*p); ++*(p); *p++; (*p)++; *(p)++; *++p; *(++p); I know, this is kind of messy in ...
Dinesh's user avatar
  • 16.5k
136 votes
3 answers
10k views

Going through some C interview questions, I've found a question stating "How to find the size of an array in C without using the sizeof operator?", with the following solution. It works, but I cannot ...
janojlic's user avatar
  • 1,299
64 votes
7 answers
124k views

Does anyone have any good articles or explanations (blogs, examples) for pointer arithmetic? Figure the audience is a bunch of Java programmers learning C and C++.
leora's user avatar
  • 198k
55 votes
8 answers
4k views

In the book, "Understanding and Using C Pointers" by Richard Reese it says on page 85, int vector[5] = {1, 2, 3, 4, 5}; The code generated by vector[i] is different from the code generated by *(...
Evan Carroll's user avatar
54 votes
5 answers
6k views

Is the behaviour of this code well defined? #include <stdio.h> #include <stdint.h> int main(void) { void *ptr = (char *)0x01; size_t val; ptr = (char *)ptr + 1; val = (...
David Ranieri's user avatar
51 votes
4 answers
3k views

Consider the following code: int* p1 = new int[100]; int* p2 = new int[100]; const ptrdiff_t ptrDiff = p1 - p2; int* p1_42 = &(p1[42]); int* p2_42 = p1_42 + ptrDiff; Now, does the Standard ...
Sergey's user avatar
  • 8,306
47 votes
5 answers
3k views

Is it possible, for a pointer variable p, that p<(p+1) is false? Please explain your answer. If yes, under which circumstances can this happen? I was wondering whether p+1 could overflow and be ...
akarapatis's user avatar
42 votes
2 answers
25k views

Considering you can (can't think of a great way to put it, but) manipulate pointers in Go, is it possible to perform pointer arithmetic like you would in C, say for iterating over an array? I know ...
user avatar
39 votes
1 answer
14k views

When trying to print the first command line argument: std::cout << argv[0] << std::endl; clang-tidy gives the warning: warning: 'do not use pointer arithmetic' from [...
user7119460's user avatar
  • 1,551
38 votes
12 answers
13k views

I keep reading that, in C, using pointer arithmetic is generally faster than subscripting for array access. Is this true even with modern (supposedly-optimizing) compilers? If so, is this still the ...
John Rudy's user avatar
  • 38k
33 votes
1 answer
2k views

Here is a smart pointer: std::shared_ptr<char> p(new char[size]) which represents array filled with raw binary file content. After (and only after) the whole array is copied from file to RAM, I ...
Alexey S. Larionov's user avatar
33 votes
2 answers
1k views

For subtraction of pointers i and j to elements of the same array object the note in [expr.add#5] reads: [ Note: If the value i−j is not in the range of representable values of type std​::​ptrdiff_­...
jotik's user avatar
  • 18.1k
30 votes
5 answers
33k views

I'm quite new at working with C++ and haven't grasped all the intricacies and subtleties of the language. What is the most portable, correct and safe way to add an arbitrary byte offset to a pointer ...
Daniel A.A. Pelsmaeker's user avatar

15 30 50 per page
1
2 3 4 5
51