This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main (void) | |
| { | |
| unsigned long i = 1; | |
| printf ("0\n"); | |
| while (((i & 0xffff0000) >> 16) + (i & 0xffff) <= 0xffff) { | |
| printf ("%d\n", i & 0xffff); | |
| i = ((i & 0xffff) << 16) | ((i >> 16) + (i & 0xffff)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int fib(n) | |
| { | |
| return (n>2) ? n : fib(n-1)+fib(n-2); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| F(n) = [(x^n) – ((1 – x)^n)]/ sqrt(5); | |
| Where x = (1 + sqrt(5))/2 = 1.6180339887 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int main() | |
| { | |
| mystruct s; | |
| s.anotherchar = 5; | |
| char* pBeginningOfS = (char*)(void*)(&s); | |
| char* pAnotherChar = pBeginningOfS + offsetof(mystruct, anotherchar); | |
| *pAnotherChar = 17; | |
| printf("anotherchar is %d", s.anotherchar); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* offsetof example */ | |
| #include <stdio.h> | |
| #include <stddef.h> | |
| struct mystruct | |
| { | |
| char singlechar; | |
| char arraymember[10]; | |
| char anotherchar; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define offsetof(a,b) ((int)(&(((a*)(0))->b))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| int main() | |
| { | |
| int a = 12, b = 25; | |
| while (b) | |
| { | |
| int carry = a & b; | |
| a = a ^ b; | |
| b = carry << 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int num = 1; | |
| if(*(char *)&num == 1) | |
| printf("Little-Endian\n"); | |
| else // will be NULL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main() | |
| { | |
| int val; | |
| printf("print the number of characters so far %n doesnt matter what you write here\n", &val); | |
| printf("val = %d\n", val); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| printf("%d\n",printf("%d",printf("%d",i))); | |
| printf("%d\n",printf("%d",printf("%d",43))); => 43 | |
| printf("%d\n",printf("%d",2)); => 2 | |
| printf("%d\n",1); => 1 |