Sunday, January 4, 2009

CProgramming operator Question with Detail Explanation



Q(1)
void main()
{
int p=7,r;
if(p=2)
{
r=sizeof(p=11);
}
else
{
int r=3;
}
printf("%d %d",p,r);
}

output: 2 2
explanation :
if(p=2)
here p=2
so if(2) is true.
now
r=sizeof(p=11)
sizeof operator never assign value to variable which is written inside the ().
till now p=2.
sizeof operator always return the size of data type which is written inside the ()
here p is integer data type so sizeof operator will assign value 2 to the r.
Q(2) write a program for writing binary equivalent value of any decimal number ?

Program:-

program for writing binary equivalent value of any decimal number
void main()
{
int value,i;
scanf("%d",&value);
for(i=0;i<16;i++)>>i)
{
printf("1");
}
else
{
printf("0");
}
}
getch();
}

Q(3) Write a program to subtract two number without using subtraction operator ?
program:-

subtract two number without using subtraction operator
void main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=a+~b+1;
printf("%d",c);
getch();
}

Q(4) Write a program to add two number without using addition operator?
program:-

add two number without using addition operator
void main()
{
int a,b,c;
clrscr();
scanf("%d%d",&a,&b);
c=a-~b-1;
printf("%d",c);
getch();
}

No comments:

Blog List