More C code
parent
a6d1d6ce77
commit
14ef6b3ba0
@ -0,0 +1,22 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void void_callback(void (*p_func)())
|
||||||
|
{
|
||||||
|
printf("Wrapped function start\n");
|
||||||
|
(*p_func)(); //callback
|
||||||
|
printf("There I called your shitty function\n");
|
||||||
|
};
|
||||||
|
|
||||||
|
void say_dirp()
|
||||||
|
{
|
||||||
|
printf("DIRP!!!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
void (*ptr)() = &say_dirp; // Ok so this is a weird way to declare pointer to a function but I guess that's what c has.
|
||||||
|
|
||||||
|
void_callback(ptr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("CHAR_BIT : %d\n", CHAR_BIT);
|
||||||
|
printf("CHAR_MAX : %d\n", CHAR_MAX);
|
||||||
|
printf("CHAR_MIN : %d\n", CHAR_MIN);
|
||||||
|
printf("INT_MAX : %d\n", INT_MAX);
|
||||||
|
printf("INT_MIN : %d\n", INT_MIN);
|
||||||
|
printf("LONG_MAX : %ld\n", (long)LONG_MAX);
|
||||||
|
printf("LONG_MIN : %ld\n", (long)LONG_MIN);
|
||||||
|
printf("SCHAR_MAX : %d\n", SCHAR_MAX);
|
||||||
|
printf("SCHAR_MIN : %d\n", SCHAR_MIN);
|
||||||
|
printf("SHRT_MAX : %d\n", SHRT_MAX);
|
||||||
|
printf("SHRT_MIN : %d\n", SHRT_MIN);
|
||||||
|
printf("UCHAR_MAX : %d\n", UCHAR_MAX);
|
||||||
|
printf("UINT_MAX : %u\n", (unsigned int)UINT_MAX);
|
||||||
|
printf("ULONG_MAX : %lu\n", (unsigned long)ULONG_MAX);
|
||||||
|
printf("USHRT_MAX : %d\n", (unsigned short)USHRT_MAX);
|
||||||
|
|
||||||
|
printf("\nStorage size for float : %d \n", sizeof(float));
|
||||||
|
printf("FLT_MAX : %g\n", (float)FLT_MAX);
|
||||||
|
printf("FLT_MIN : %g\n", (float)FLT_MIN);
|
||||||
|
printf("-FLT_MAX : %g\n", (float)-FLT_MAX);
|
||||||
|
printf("-FLT_MIN : %g\n", (float)-FLT_MIN);
|
||||||
|
printf("DBL_MAX : %g\n", (double)DBL_MAX);
|
||||||
|
printf("DBL_MIN : %g\n", (double)DBL_MIN);
|
||||||
|
printf("-DBL_MAX : %g\n", (double)-DBL_MAX);
|
||||||
|
printf("Precision value: %d\n", FLT_DIG);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void swap(int *, int *); // defined
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int a = 21;
|
||||||
|
int b = 17;
|
||||||
|
int *p_a = &a; //address of operator. Generates a pointer to the memory location og the object.
|
||||||
|
int *p_b = &b; // Assigning the pointer &b to the *p_b int pointer variable declared in line
|
||||||
|
|
||||||
|
swap(p_a, p_b); //could have done swap(&a, &b); simulates pass-by-reference
|
||||||
|
|
||||||
|
printf("main: a = %d, b = %d\n", a, b);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap(int *a, int *b)
|
||||||
|
{
|
||||||
|
int t = *a; // dereference the pointer to save it's object's value to the t variable
|
||||||
|
*a = *b; // *a and *b are both derefencing the int objects at those memory locations. This overwrites the object at location a with b's value.
|
||||||
|
*b = t; // dereference the b pointer and overwrite it's object's value with the value of t.
|
||||||
|
}
|
Loading…
Reference in New Issue