Skip to content

Instantly share code, notes, and snippets.

@mezcel
Last active April 18, 2020 10:38
Show Gist options
  • Select an option

  • Save mezcel/62f85669d9d901d364f3779198e1f5b6 to your computer and use it in GitHub Desktop.

Select an option

Save mezcel/62f85669d9d901d364f3779198e1f5b6 to your computer and use it in GitHub Desktop.
C notes

C snipits

Some refresher C concepts and use cases.

  • Notes
  • web search answers
  • usecases that i find meaningful
  • reminders and sanity checks

Online quck refference:

/* Equivalent bitwise and logical operator tests */
#include <stdio.h> // printf()
// Prototypes
void bitwise_1compliment();
void numberArray();
void charArray();
int main( void ) {
bitwise_1compliment();
numberArray();
charArray();
return 0;
}
/////////////
void bitwise_1compliment() {
unsigned int a = 0b1101; // 1101 // 13
unsigned int b = 0b0001; // 0001 // 1
unsigned int c;
printf( "\nBitwise 1 Compliment \n" );
c = a ^ b;
printf( "\n\t0b1101\t^ 0b0001\n\t%d\t^ %d\t= %d\n", a, b, c );
unsigned char a1 = 1; // 0001 // 1
unsigned char b1 = 3; // 0011 // 3
unsigned char c1;
c1 = a1 ^ b1;
c1 = c1 ^
printf( "\n\t0001\t^ 0011\n\t%d\t^ %d\t= %d \n", a1, b1, c1 );
}
void numberArray() {
printf( "\nNumber Array \n" );
int myArr[4] = { 0, 0, 0, 0 };
int a = 1;
printf( "\n\tmyArr[4] = { 0, 0, 0, 0 }\t%d%d%d%d \n", myArr[0], myArr[1], myArr[2], myArr[3] );
myArr[2] = a;
printf( "\n\tmyArr[2] = 1\t\t\t%d%d%d%d \n", myArr[0], myArr[1], myArr[2], myArr[3] );
}
void charArray() {
printf( "\nChar Array \n" );
char myArr[4] = "0000";
char a[1] = "1";
printf( "\n\tchar myArr[4] = \"0000\"\t%s \n", myArr );
myArr[2] = a[0];
printf( "\n\ta[1] = \"1\"\n\tmyArr[2] = a[0]\t\t%s\n", myArr );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment