---
title: "Effect of Ptr++ on pointer"
subject: "Computer Programming"
chapter: 9
key: "semester_1/computer_programming:ptr-increment-bytes"
source: https://www.bctengineer.com/q/semester_1/computer_programming/ptr-increment-bytes
site: BCT Engineering
---

# Effect of Ptr++ on pointer

Computer Programming · Chapter 9: Pointers

- Asked in: 2072 Kartik, 2 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/ptr-increment-bytes
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-9

## Question

If Ptr is a pointer to user defined type or basic type, by how many bytes is Ptr incremented when the statement Ptr++ is executed?

## Short answer

Ptr++ increments by sizeof(the pointed-to type) bytes. For char*: 1 byte, int*: typically 4 bytes, double*: 8 bytes, and for a struct pointer: size of the struct including padding (e.g., 16 bytes in the example).

## Answer

`Ptr++` increases the pointer by **sizeof(the type it points to)** bytes, so that it points to the next element of that type. The compiler scales the increment automatically.

- `char *`: 1 byte
- `int *`: 4 bytes (typical)
- `double *`: 8 bytes
- pointer to a structure: `sizeof(struct)`, including any padding

```c
#include <stdio.h>

struct rec { char name[10]; int roll; };

int main(void)
{
    char c[2]; int i[2]; double d[2]; struct rec r[2];
    char *pc = c; int *pi = i; double *pd = d; struct rec *pr = r;

    printf("char   : %ld byte(s)\n", (long)((char *)(pc + 1) - (char *)pc));
    printf("int    : %ld byte(s)\n", (long)((char *)(pi + 1) - (char *)pi));
    printf("double : %ld byte(s)\n", (long)((char *)(pd + 1) - (char *)pd));
    printf("struct : %ld byte(s)\n", (long)((char *)(pr + 1) - (char *)pr));
    return 0;
}
```

Output (typical 64-bit system):

```text
char   : 1 byte(s)
int    : 4 byte(s)
double : 8 byte(s)
struct : 16 byte(s)
```

The structure takes 16 bytes: 10 for `name`, 2 bytes of padding so that `roll` starts at a multiple of 4, and 4 for `roll`.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. By how many bytes does Ptr++ change the pointer?
   A. Always 1
   B. Always 4
   C. sizeof the type it points to
   D. sizeof the pointer itself
   Answer: C. The compiler scales the increment by the size of the pointed type so it reaches the next element. (Key point: Increment amount)

2. Which set gives the increments for char *, int * and double * on a typical system?
   A. 1, 2, 4
   B. 1, 4, 8
   C. 4, 4, 8
   D. 1, 8, 8
   Answer: B. char is 1 byte, int is typically 4 bytes, and double is 8 bytes. (Key point: Typical sizes)

3. For a pointer to a structure, Ptr++ moves by:
   A. The size of the first member
   B. sizeof(struct), including any padding
   C. 1 byte
   D. The number of members
   Answer: B. The step is the whole structure size including padding. (Key point: Structure pointer)

## Related in Computer Programming

- [Switch versus user defined function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-user-function) — Computer Programming, chapter 5
- [Significance of user defined functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asignificance-user-defined-functions) — Computer Programming, chapter 6
- [Copy string converting lower to upper using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-array-elements-copy-string-upper) — Computer Programming, chapter 9, asked 3×
- [Nested if with flowchart](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Anested-if-flowchart) — Computer Programming, chapter 5
- [Conditional operator vs if-else; digit sum](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aconditional-operator-vs-ifelse) — Computer Programming, chapter 5

## Related in other subjects

- [Convert user-defined type to basic type](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Auser-to-basic-conversion) — Object Oriented Programming, chapter 5
- [Muster roll for user's committee project](https://www.bctengineer.com/question.md?key=semester_8%2Fconstruction_management%3Amuster-roll-user-committee) — Construction Management, chapter 8
- [Why n-type has many conduction electrons](https://www.bctengineer.com/question.md?key=semester_3%2Felectrical_engineering_material%3Antype-electrons-conduction-band) — Electrical Engineering Material, chapter 6
- [How many times more acidic: pH 6.5 and 7.8](https://www.bctengineer.com/question.md?key=semester_5%2Fwater_supply_engineering%3Aph-acidic-j66) — Water Supply Engineering, chapter 4
