Pages

Sunday, July 10, 2011

C - Logics part-1

Follow the following programs written below :-
1. 

#include<stdio.h>
int lmn();
int pqr();
int ppp();
int hhh();
int fff();
void main()
{
 printf("%d %d %d %d",lmn(), pqr(), ppp(),hhh(), fff());
}
int lmn()
{
printf("One\n");
return 1;
}
int pqr()
{
printf("two\n");
return 2;
}
int ppp()
{
printf("Three\n");
return 3;
}
int hhh()
{
printf("Four\n");
return 4;
}
int fff()
{
printf("five\n");
return 5;
}
/* Try to understand output of this by your own.
-----------------------------------------------------------------
2.

#include<stdio.h>
void main()


{
int x,y;
x=10;
y=10;
printf("%d %d %d\n",x*y,x++,y++);


}


Output:-
121 10 10


-----------------------------------------------------------------
3.
#include<stdio.h>
void main()


{
int x,y;
x=10;
y=10;
printf("%d %d %d\n",x*y,++x,++y);


}




Output:-
121 11 11


-----------------------------------------------------------------
4.


#include<stdio.h>
void main()


{
int x,y;
x=10;
y=10;
printf("%d %d %d %d\n",x*y,--x,++x,++y);


}




Output:-
110 10 11 11

-----------------------------------------------------------------
5.


#include<stdio.h>
void main()


{
int x,y;
x=10;
y=10;
printf("%d %d %d %d\n",x*y,x--,++x,++y);


}




Output:-
110 11 11 11

-----------------------------------------------------------------
Note:- If you get doubts in any program then plz ask me by doing comments.
-----------------------------------------------------------------

2 comments:

  1. Sir Plz clear Explain the above program

    ReplyDelete
  2. ok!!!
    know it that printf() function does it process from Right to left it means that it first processes the instruction which is the first in right.
    -------------
    also know it
    if X=10;
    Y=++X;
    it means that it will first increment the value of x by 1 and then assign to y.
    thus Y=11;
    and X=11;

    if X=10;
    Y=X++;

    it means that it will first assign the value of x and then increment its value by one.
    thus
    y=10;
    x=11;

    Apply this rule to all programs.
    -----------------------------------------------

    ReplyDelete