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

Monday, October 26, 2009

Precedence of operators

#include< stdio.h >
int i ;
i = 1;
i= i+2*i++;
printf("i is now %d",i);


How it works?

This operation is performed as per the precedence rules(BODMAS- Bracket of
Division Multiplication Addition Subtraction). As per the BODMAS
the multiplication(*) has higher precedence then the addition(+) so first
Multiplication will be performed after that only the increment and addition
operation is performed.

Without Main Function

Everyone know that can't create c program without main because main is main of
c program and also main will be called first and execute. Then How it's
possible to create c program without main. Here it's the program without main.

#include< stdio.h >
#define selva(b,c,e,s,g,f,d,o) o##g##d##b
#define shark selva(n,y,s,t,a,c,i,m)
void shark()

How it works?
Obviously we can't create c program without main function. Then How this program working?!..
In this program i use main function indirectly.
## is named as merging operator. It will merge characters and produce a string.
Here i was created a function 'selva' such that it gets arguments and merge it in some order and returns that string.
And i was called the 'selva' function with arguments 'n','y','s','t','a','c','i','m'. Now track the 'selva' function cleanly. it is merging only 4 characters. By passing these arguments, it'll merge 'm','a','i','n' as 'main'. So now it'll return "main" string. And now shark=main. These operation are done while compiling because we did all these using #define. So it'll run without errors.