pointeur arithmétique en c
#include <stdio.h>
int main()
{ // pointer Arithmetic
printf("\nPointer Arithmetic\n");
int i, *ptr;
int num[] = {10, 100, 200};
// assign array address to pointer
ptr = num;
// value of ptr = address of num
printf("\n Value of ptr ----- %x\n", ptr);
for (i = 0; i < 3; i++)
{
printf(" Address of num[%d] = %x\n", i, ptr);
printf(" Value of num[%d] = %d\n", i, *ptr);
ptr++; // next address space Jumps by 4 due to the size of an int in memory.
}
// String Array arithmetic
// I'm not recommending you do this
printf("\n\nString Arithmetic\n\n");
char *str[12] = {"C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"};
printf(" Array value at index 11 is %s\n", str[11]);
// address of array at index
printf(" Address of array at index 0 %x\n", str[0]);
// address of array
printf(" Address of array %x\n", *str);
// increases the memory address by one.
str[0]++;
// address of array
printf(" Address of array after array has been incremented by one %x\n", *str);
return 0;
Dirty Moose