Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22171

Pre-increment operator with and without pointer in C [duplicate]

$
0
0

This question already has an answer here:

I am running gcc 7.4.0 on ubuntu 18.04. I compiled and ran the following code

#include<stdio.h>

int main() {
  int *p;
  int a[2];
  a[0] = 100;
  a[1] = 200;
  p = a;
  int b = 10;
  printf("%d\t%d", ++*p, *p);
  printf("\n%d\n", *p);

  printf("%d\t%d", ++b, b);
  printf("\n%d\n", b);
  return 0;
}

I am getting this output:

101     100
101
11      11
11

Why is the pre-increment operator behaving differently with the integer value pointed by pointer and the ordinary integer value?


Viewing all articles
Browse latest Browse all 22171


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>