News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Post and Pre Operators

Started by thiruvasagamani, Sep 22, 2008, 11:27 AM

Previous topic - Next topic

thiruvasagamani

program in postincrement

#include < stdio.h >
#include < conio.h >
main()
{
int a=7;
printf("%d\n",a++);//her' a' value is 7
printf("%d\n",a);//but here ' a' value is 8
getch();
}
o/p: a = 8

NOTE :
a++ in printf means
i.Displays current value 'a'
ii. Increment 'a' by 1 , a=a+1

15.Program on preincrement

#include < stdio.h >
#include < conio.h >
main()
{
int a=7;
printf("%d\n",++a);//here 'a' value is 8
printf("%d\n",a);//here 'a' value also 8
getch();
}

o/p: a value is 8

Note:
++a in printf means
i.increment 'a' by 1,a=a+1
ii.Displays new value of 'a'

Program on preincrement and postincrement

#include < stdio.h >
#include < conio.h >
main()
{
int a= 7;
printf("%d\t%d\t%d\t%d\n", a++,++a,a++,++a);
printf("%d\n", a);
getch();
}
o/p: 10, 10, 8, 8
11


NOTE:
Parameters evaluation is always from right to left,this is due to stacks.Last parameter is first evaluated

program on comparison of variables


#include < stdio.h >
#include < conio.h >
main()
{
int a= 25;
printf("%d\t%d\t%d\n", a==25,a=35,a==45);
printf("%d\n",a);//here value is 35
getch();
}
o/p:
0,35,0
35


program on power() function

#include < stdio.h >
#include < conio.h >
main()
{
int a= 4,b;
b= pow(a++,++a);
printf("a=%d\n",a);//here 'a' value is 6
printf("b=%d\n",b);
getch();
}
o/p:
6,125
Thiruvasakamani Karnan