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..

Friday, February 12, 2010

13

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


click Output


How?


#define is used to define a constant.
in this program 3+2 is defined for 'a'.
so whenever you use a variable,it'll replace the a with 3+2.

b=a*2; in this expression a is replaced by 3+2 while creating expanded code.
so it'll become like this b=3+2*2;

we know that '*' has high precedence than +.
2*2 will multiplied and it'll added to 3.
so b=7.

Escape Sequence characters

#include < stdio.h >
main()
{
printf("sharksr");
printf("\bselvan");
printf("\rsabari");
printf("\n shark selva");
printf("\t tab");
}

OUTPUT


sabariselva
sharkselva     

How?


this escape sequence operators are used in printf function to design our output in
certain structure.
\n Next line
\t Tab
\r Carriage return( returns to the first of the line).
\b Backspace(backspace one character )

12

#include < stdio.h >
main()
{
char r[]="orns"
printf(" %c",r[1]);
printf(" %c",1[r]);
}