Y
Yuval K
I've encountered something odd...
A friend of mine just started C and had this problem.
Here's very simple (bugged) program which still works correctly.
#include <stdio.h>
int main()
{
char b,radius,area,a;
printf("Ente 3 numbers:\n");
scanf("%d",&area);
scanf("%d",&radius);
scanf("%d",&b);
printf("%c%c%c\n",radius,area,b);
return 0;
}
Of course there's problem with conversion from int to char etc, but it
still reads and prints the symbols that you've entered.
On the other hand if you move 'b' to the end of declaration it doesn't
print the 3 letters as it should.
int main()
{
char radius,area,a, b;
printf("Ente 3 numbers:\n");
scanf("%d",&area);
scanf("%d",&radius);
scanf("%d",&b);
printf("%c%c%c\n",radius,area,b);
return 0;
}
I've used gcc compiler.
Could someone explain me the reason why the order of declaration
changes the output?
Thanks.
A friend of mine just started C and had this problem.
Here's very simple (bugged) program which still works correctly.
#include <stdio.h>
int main()
{
char b,radius,area,a;
printf("Ente 3 numbers:\n");
scanf("%d",&area);
scanf("%d",&radius);
scanf("%d",&b);
printf("%c%c%c\n",radius,area,b);
return 0;
}
Of course there's problem with conversion from int to char etc, but it
still reads and prints the symbols that you've entered.
On the other hand if you move 'b' to the end of declaration it doesn't
print the 3 letters as it should.
int main()
{
char radius,area,a, b;
printf("Ente 3 numbers:\n");
scanf("%d",&area);
scanf("%d",&radius);
scanf("%d",&b);
printf("%c%c%c\n",radius,area,b);
return 0;
}
I've used gcc compiler.
Could someone explain me the reason why the order of declaration
changes the output?
Thanks.