Unexpected result in C program

1

In this code:

#include <stdio.h>
#include <stdlib.h>
int main() {
int x, y = 10;
//incrementa depois atribui
y = ++x;
printf("x = %d\n", x);
printf("y = %d\n", y);
system("pause");
return 0;

}

Compiled and executed in codeblocks it returns the size of the variable plus the increment; The result should be x = 11; and y = 11; In ideone it returns x and y = 1; The difference between x ++; e ++ x; is that x ++ = 10 + 1 and ++ x = 1 + 10?

    
asked by anonymous 11.05.2015 / 13:48

1 answer

3

You are not starting the variable x

here:

int x, y = 10;

should be

int x = 10, y = 10;
    
11.05.2015 / 13:52