Macro to swap any two variable int, char, float, struct etc.. /* Generic Swap macro*/ #define swap (a, b, type) {type t = a; a = b; b = t; } Call the macro like this: swap(a,b,int) swap(a,b,str)
Category: Programming
String initialization
char *a = “Hi how are you??” a[0] = ‘h’; This will output Segmentation fault Because, such an intialization will create const memory and it can’t be modified. While char a[] = “Hi how are you??” a[0] = ‘h’ willContinue reading… String initialization
More on structures and unions
typedef does not define a new data type There are three main reasons for using typedefs: * It makes the writing of complicated declarations a lot easier. This helps in eliminating a lot of clutter in the code. * ItContinue reading… More on structures and unions
Operator Precedence Chart for referance
Operator Type Operator Execution Order Primary Expression Operators () [] . -> expr++ expr– left-to-right Unary Operators * & + – ! ~ ++expr –expr (typecast) sizeof() right-to-left Binary Operators * / % left-to-right + – >> >=
precidence of , and =
#include int main(int argc,char *argvp[]) {
precidence of * and ++
# include main () {
Order of arguments passed to a function
#include void fn (int, int); main () {
Evaluation of If statement
#include main () {
Some Nice Perl Tips
Alias of perl builtin variables ========================================================== use English The English module provides aliases for the Perl builtin variables. $ARG is equivalent to $_ $1 equivalent to $MATCH $` equivalent to $PREMATCH $’ equivalent to $POSTMATCH Locate the source path ofContinue reading… Some Nice Perl Tips
Evaluation sequency of print statement
#!/usr/bin/perl print “Hey! “, mysub(“foo”); sub mysub { my $a=shift; print “$a “; } It outputs: foo Hey! 1 Because print evaluates its rightmost terms first, the “mysub()” is called before the “Hey! ” is printed. That prints “foo” andContinue reading… Evaluation sequency of print statement