HAY PROGRAMMERS,
I HAVE A PROBLEM WITH VISUAL STUDIO 2013 C++ CODE.
I HAVE THIS CODE:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <stdio.h>
__int8 a;
__int8 b=0;
void main(void)
{
for (int i=0; i < 6; i++)
{
scanf("%ld", &a);
printf("b is equal to: %ld", b);
b++;
}
}
|
THIS CODE COMPILES WITHOUT ERRORS.
WHAT THIS DOES IS THAT IT CREATES INTEGER VARIABLE WHICH IS 8 BITS LONG, ASKS USER TO ENTER A NUMBER IN THAT VARIABLE SIX TIMES. (NO POINT OF DOING THIS SIX TIMES, BUT IGNORE THIS FOR NOW).
ALSO, IT HAS A 8 BIT INTEGER VARIABLE WHICH COUNTS THE NUMBER OF TIMES USER ENTERED A NUMBER.
BUT THE PROBLEM IS THAT FOR SOME REASON COMPILER IGNORES b++; LINE.
OUTPUT FROM THIS CODE IS:
1 2 3 4 5 6
|
b is equal to: 0
b is equal to: 0
b is equal to: 0
b is equal to: 0
b is equal to: 0
b is equal to: 0
|
WHY?
I TYPED b++; AND IT SHOULD BE GRATER IN EVERY ITTERATION.
WHAT IS ODD IS THAT IF I REMOVE scanf FUNCTION OUTPUT IS:
1 2 3 4 5 6
|
b is equal to: 0
b is equal to: 1
b is equal to: 2
b is equal to: 3
b is equal to: 4
b is equal to: 5
|
ALSO, IF I DECLARE b AS __int16 AND NOT __int8 IT WORKS CORRECT WITH OR WITHOUT scanf.
1 2 3 4 5 6
|
b is equal to: 0
b is equal to: 1
b is equal to: 2
b is equal to: 3
b is equal to: 4
b is equal to: 5
|
WHY b CAN NOT BE DECLARED AS __int8 IN THIS LOOP?
OR WHY IS scanf CAUSEING COMPILER TO IGNORE b++ COMMAND?
THANX