Dear All,
I am running C programs on DEV-C++. Its 32-bits compiler like MS visual..
Kindly go through the following program.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
main()
{
char ch;
unsigned char u_ch;
int i;
unsigned u_i;
short int s;
unsigned short u_s;
long l;
unsigned long u_l;
float f;
double d;
long double l_d;
/*Entering the data*/
printf("1. Enter character = ");
fflush(stdin);
scanf("%c", &ch);
printf("2. Enter unsigned character = ");
fflush(stdin);
scanf("%c", &u_ch);
printf("3. Enter integer = ");
scanf("%d", &i);
printf("4. Enter unsigned integer = ");
scanf("%u", &u_i);
printf("5. Enter short integer = ");
scanf("%d", &s);/*
printf("6. Enter unsigned short integer = ");
scanf("%u", &u_s);
printf("7. Enter long integer = ");
scanf("%ld", &l);
printf("8. Enter unsigned long integer = ");
scanf("%lu", &u_l);
printf("9. Enter float = ");
scanf("%f", &f);
printf("10. Enter double = ");
scanf("%lf", &d);
printf("11. Enter long double = ");
scanf("%Lf", &l_d);
/*Printing data*/
printf("1. Character = %c\n\n", ch);
printf("2. Unsigned Character = %c\n\n", u_ch);
printf("3. Integer = %d\n\n", i);
printf("4. Unsigned integer = %u\n\n", u_i);
printf("5. Short = %d\n\n", s);/*
printf("6. Unsigned short = %u\n\n", u_s);
printf("7. Long = %ld\n\n", l);
printf("8. Unsigned long = %lu\n\n", u_l);
printf("9. Float = %f\n\n", f);
printf("10. Double = %lf\n\n", d);
printf("11. Long double = %Lf\n\n\n", l_d);
system("pause");
}
Here, I can enter the data of all data type in section “/*Entering the data*/”. I enter 1 (i) for integer, 2 (u_i) for unsigned integer and 3 (s) for short. And others also.
But my compiler prints 0 for unsigned integer u_i.
I.e. Compiler assigns 0 to unsigned integer u_i, even I entered value 2 to it.
When I use same program to TURBO – C, I am getting right output.
Can any body help?
Rpstata