A
aarklon
Hi all,
I was reading the book "C interview Questions" By J. Rajaram
published in india by firewall media, after going through the book
i have the following doubts
1) why the following program is not showing compilation error in the
lines no: of arguments in the function declaration and function
definition do not match???
void swap();
int main(void)
{
int x=10,y=8;
swap(&x,&y);
printf("\n x = %d y = %d",x,y);
puts("");
return(EXIT_SUCCESS);
}
void swap(int *a, int *b)
{
*a ^= *b,*b ^= *a, *a ^= *b;
}
2) why (~0 == (unsigned int)-1)
can any body explain???
from reading CLC book "C Unleashed" i know that -X =(MAX - X)+1
1.e -x =~x +1 ,so from this relation how can we get (~0 == (unsigned
int)-1)
3)why does printf("%d %f",14.0,2.50); gives o/p as 0 0.00000
4)why printf("%d",-1>>3); gives o/p as -1
5)
main()
{
int i= -1;
-i;
printf("i = %d -i = %d",i,-i);
}
the o/p is given as i = -1, -i =1
but when this pgm is run
main()
{
int i= -1;
+i;
printf("i = %d +i = %d",i,-i);
}
the o/p is given as i = -1, +i = -1
so what exactly is the purpose of unary + operator and unary -
operator??
6)
why the program
main()
{
int i=5; j=10;
i=i^=j ||i;
printf("i= %d",i);
}
gives o/p as 4???
as far my understanding goes result of an expression involving
logical operator is of boolean nature
I was reading the book "C interview Questions" By J. Rajaram
published in india by firewall media, after going through the book
i have the following doubts
1) why the following program is not showing compilation error in the
lines no: of arguments in the function declaration and function
definition do not match???
void swap();
int main(void)
{
int x=10,y=8;
swap(&x,&y);
printf("\n x = %d y = %d",x,y);
puts("");
return(EXIT_SUCCESS);
}
void swap(int *a, int *b)
{
*a ^= *b,*b ^= *a, *a ^= *b;
}
2) why (~0 == (unsigned int)-1)
can any body explain???
from reading CLC book "C Unleashed" i know that -X =(MAX - X)+1
1.e -x =~x +1 ,so from this relation how can we get (~0 == (unsigned
int)-1)
3)why does printf("%d %f",14.0,2.50); gives o/p as 0 0.00000
4)why printf("%d",-1>>3); gives o/p as -1
5)
main()
{
int i= -1;
-i;
printf("i = %d -i = %d",i,-i);
}
the o/p is given as i = -1, -i =1
but when this pgm is run
main()
{
int i= -1;
+i;
printf("i = %d +i = %d",i,-i);
}
the o/p is given as i = -1, +i = -1
so what exactly is the purpose of unary + operator and unary -
operator??
6)
why the program
main()
{
int i=5; j=10;
i=i^=j ||i;
printf("i= %d",i);
}
gives o/p as 4???
as far my understanding goes result of an expression involving
logical operator is of boolean nature