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: C/C++
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 () {