Skip to content

Instantly share code, notes, and snippets.

View jacobabrahamb4's full-sized avatar

Jacob Abraham jacobabrahamb4

View GitHub Profile
@jacobabrahamb4
jacobabrahamb4 / use_pointers_to_pointers.c
Created April 12, 2013 07:18
using pointers to pointers in c
//taken from http://stackoverflow.com/questions/894604/passing-dynamically-allocated-integer-arrays-in-c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ELEMENTS 5
/*
@jacobabrahamb4
jacobabrahamb4 / pointers_to_pointers_2.c
Created April 12, 2013 07:26
pointers_to_pointers_2
// taken from http://beej.us/guide/bgc/output/html/multipage/morestuff.html#pt2pt
#include <stdio.h>
#include <stdlib.h>
void get_string(int a, char **s)
{
printf("s in get_string is : %p\n", s);
switch(a)
{
case 0:
@jacobabrahamb4
jacobabrahamb4 / function_pointers.c
Created April 12, 2013 07:29
function_pointers
#include <stdio.h>
#include <stdlib.h>
typedef int* intPtr;
typedef float (*fPtr) (float, float);
float plus(float a, float b){return a+b;}
float minus(float a, float b){return a-b;}
float multiply(float a, float b){return a*b;}
float divide(float a, float b){return a/b;}
@jacobabrahamb4
jacobabrahamb4 / convert_to_uppercase.c
Last active December 16, 2015 03:38
convert to upper case
// find more explanations here
// https://www.securecoding.cert.org/confluence/display/seccode/STR30-C.+Do+not+attempt+to+modify+string+literals
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *strptr = NULL, *copy = NULL;
strptr = "Jacob Abraham"; // this will be stored in a read only location hence cannot be modified.
@jacobabrahamb4
jacobabrahamb4 / debugging_macros.c
Last active December 16, 2015 03:39
using some built in macros in c for debugging purpose
// its documented here in this link http://www.delorie.com/gnu/docs/gcc/cpp_21.html
#include <stdio.h>
#include <stdlib.h>
#define PRINTINFO(message) print_info(__FILE__, __LINE__, __DATE__, __TIME__, message)
void print_info(const char* file,int line, const char* date, const char* time, const char* message)
{
printf("FILE is : %s\n ", file);
@jacobabrahamb4
jacobabrahamb4 / bitwise.c
Created April 13, 2013 13:41
using bitwise operators....
//http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
#include <stdio.h>
void check_even_odd(int);
void check_nth_bit_is_set(int , int);
int set_the_nth_bit(int,int);
int unset_the_nth_bit(int,int);
int toggle_nth_bit(int, int);
int turn_off_the_righmost_one(int);
@jacobabrahamb4
jacobabrahamb4 / pipelining.txt
Last active December 16, 2015 04:39
Pipelining concept in computer architecture
//http://discuss.itacumens.com/index.php?topic=7635.0
Pipelining concept in computer architecture
In this Module, we have three lectures,
1. Introduction to Pipeline Processor
2. Performance Issues
3. Branching
@jacobabrahamb4
jacobabrahamb4 / abs_float.c
Created April 14, 2013 14:16
absolute value of float
#include<stdio.h>
int main()
{
float x;
printf("Enter the float number:\n");
scanf("%f", &x);
// copy and re-interpret as 32 bit integer
int casted_to_int = *(int*)&x;// float pointer is converted to an integer pointer and dereferenced.
@jacobabrahamb4
jacobabrahamb4 / single_linked_list.c
Created April 18, 2013 18:01
single linked list, only functions are included, will be implemented later.....
//http://www.zentut.com/c-tutorial/c-linked-list/
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
node* next=NULL;
} node;
@jacobabrahamb4
jacobabrahamb4 / stack_using_linked_lists.c
Created April 18, 2013 18:33
stack using linked lists, will be edited later.
//http://www.zentut.com/c-tutorial/c-stack-using-pointers/
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node* next;
} node;