Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

11,402 questions

15,552 answers

573 users

How to do pointer arithmetic in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    int a = 7, b = 13;

    int *p1, *p2, *p3;

    p1 = &a;    
    p2 = &b;    

    printf("p1 = %p\n", p1);
    printf("p2 = %p\n", p2);

    int c = *p1 + *p2;
    printf("*p1 + *p2 = %d\n", c);

    p3 = p1;
    printf("p3 = %p *p3 = %d\n", p3, *p3); 

    (*p1)++;
    printf("(*p1)++ = %d a = %d\n", *p1, a); 

    (*p2)--;
    printf("(*p2)-- = %d b = %d\n", *p2, b); 

    printf("*p2 - *p1 = %d\n", *p2 - *p1); 
      
    return 0;
}
  
  
  
/*
run:
  
p1 = 000000000062FE2C
p2 = 000000000062FE28
*p1 + *p2 = 20
p3 = 000000000062FE2C *p3 = 7
(*p1)++ = 8 a = 8
(*p2)-- = 12 b = 12
*p2 - *p1 = 4
 
*/

 




answered Jul 11 by avibootz
...