We will see it with an example, Lets calculate pow(x,23) x^23 = x^22 * x x^22 = x^11 * x^11 x^11 = x^10 * x x^10 = x^5 * x^5 x^5
Author: vamsipavan
pseudo random number generator
The pseudo random numbers can be generated using linear congruential method. Successive members of the linear congruential sequence {x} are generated using the expression: X_n+1 = ( a*X_n + b) mod m
sizeof operator
sizeof(‘a’) = 4
Index into arrays
main () {
Function pointers, static char
typedef int abc (int a, char *b); int func2 (int a, char *b){
Delete a node from a Double Linked list, with out using any extra variables
DLNode *DelNode(DLNode *aHead, int DelValue) {
Reverse a Double Linked list
DLNode *revList(DLNode *aHead) {
Macros
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)
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
Swap two variables in one line with out using temporary variable
a = a+b-(b=a) OR a = a^b^(b=a) And both of them will work also for chars and stuff ….