Introduction To Programming

Why programs ? Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time..

Sunday, February 14, 2010

20

#include< stdio.h >
main()
{
char a[]="srini selva";
printf("%c\n",*(&a[1]));
printf("%s\n",a+6);
printf("%c\n",*(a+6));
}


output


r
selva
s

19

#include< stdio.h >
main( )
{
int a=1,b=2;
(a+b)++;
printf("%d %d",a,b);
}


Output:


compilation error:
Lvalue required.


Logic:


we can increment the value of variables not constant. In this program (a+b)++ is given. (3)++ is not valid. We can't store values in constant. i.e., 3=3+1 is wrong. In left side we should use variable not a constant. So it shows "Lvalue require."

18

#include < stdio.h >
main()
{
int a=1;
void function(int ,int ,int ); //Function Declaration
function(++a,a,a++); //function call
}
void function(int i,int k,int j)
{
printf("%d %d %d",i,k,j);
}


Output


3      2       1


Logic:


a++     post increment
++a     pre increment
( ) associativity(in which direction operation done) is right to left( i.e., <--)
so first it starts from right i.e.,a++ (post increment) so a=1 is passed to j.
and a will be incremented to 2,then a=2 is passed to k.and finally ++a is preincrement so a=3 and it's passed to i.