Skip to content

Instantly share code, notes, and snippets.

View bragboy's full-sized avatar
🧘
Inner peace

Bragadeesh bragboy

🧘
Inner peace
View GitHub Profile
#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));
int fib(n)
{
return (n>2) ? n : fib(n-1)+fib(n-2);
}
F(n) = [(x^n) – ((1 – x)^n)]/ sqrt(5);
Where x = (1 + sqrt(5))/2 = 1.6180339887
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;
}
/* offsetof example */
#include <stdio.h>
#include <stddef.h>
struct mystruct
{
char singlechar;
char arraymember[10];
char anotherchar;
};
#define offsetof(a,b) ((int)(&(((a*)(0))->b)))
#include<stdio.h>
int main()
{
int a = 12, b = 25;
while (b)
{
int carry = a & b;
a = a ^ b;
b = carry << 1;
}
#include <iostream>
using namespace std;
int main()
{
int num = 1;
if(*(char *)&num == 1)
printf("Little-Endian\n");
else // will be NULL
#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;
}
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