473,903 Members | 5,705 Online

# pls help me

2 New Member
Some common confusions
.I am reading Ritchie and Deitel and practising questions from Yashwant Kanetkar...Here are some of the confusions i am having..your help is required....

Q1)

#include<stdio. h>
int main()
{
printf("%d \n",-5%-4);
printf("%d\n",-5%4);
printf("%d\n",5 %-4);
getch();
return 0;
}

o/p

-1
-1
1

So this implies that sign of % operator wil always be sign of the numerator??Am i correct??

Q2)

#include<stdio. h>
int main()
{
int x=3;
float y=3.0f;
double z=3.0;
if(x==y)
printf("x and y are equal\n\n");
else
printf("x and y are not equal");
if(y==z)
printf("y and z are equal\n\n");
else
printf("y and z are not equal");
if(y<3.0)
printf("I am satisfied");
getch();
return 0;
}

O/p

x and y are equal
y and z are equal

So confusion here is floating point numbers aren't stored by approximations? ?So why int =float=double here??For third case
if(y<3.0)

In yashwant kanetkar it assume it to be true as it says 3.0 is double and bigger than a float value so it would be true.....But when i run i didn't turn to be true.....

Q3)

int x=5
int y= x++ + ++x;
printf("%d %d",y,x);

pls explain.....

Similarly int x=7,y;
y=x/++x;

pls explain the o/p

The explanation given there was that ++x because of greater precedence would be evaluated first then ++x....

but in
i=1
a=++i;

If this reasoning is followed then [] has higher precedence so a=a[1] and increamenting should be done afterwards..... ..??But i hav red in Richie that it is
undefined situation.....

I am very much confused in these.....your valuable help is required

Pls also suggest a good book for practicing o/p questions....
Jan 3 '09 #1
0 1537