0

Specifically,here is my program on gcc.

#include <stdio.h>
char ga[]="abc";
void func(char ca[])
{
    printf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);
}
main()
{   
    func(ga);
    printf("%p %p %p\n",ga,&ga[0],&ga[1]);
}

And the output of it is

# ./a.out 
0x8049735 0x8049735 0x8049736 0x8049735
0x8049734 0x8049734 0x8049735

Then why the address of ca is one byte larger than the address of ga?

And why the value of ++ca is equal to ca?

Anmol Singh Jaggi
  • 8,376
  • 4
  • 36
  • 77
cain abel
  • 83
  • 5

1 Answers1

4

Change ++ca to ca and you will get the expected results.
It is not necessary that in printf("%p %p %p %p\n",ca,&ca[0],&ca[1],++ca);, the arguments will be evaluated from left to right; such behaviour is compiler dependent.
In this case, they are being evaluated from right to left; first ca is being incremented and then the printing takes place.

Anmol Singh Jaggi
  • 8,376
  • 4
  • 36
  • 77