A

@Adarsh222

Function to execute before main

C
3 years ago
#include<stdio.h> /* Apply the constructor attribute to myStartupFun() so that it is executed before main() */ void myStartupFun (void) __attribute__ ((constructor)); /* Apply the destructor attribute to myCleanupFun() so that it is executed after main() */ void myCleanupFun (void) __attribute__ ((destructor));

bitwise not

C
3 years ago
#if 0 #include<stdio.h> int main(){ int a=10;//1010 a=a | (1<<2);//1110//14 or if (1<<0)//1011 11 a=~a;//0111= -a-1=-15; printf("%d",a); }

pointer equal or not

C
3 years ago
#include <stdio.h> int main() { char *p = "hi";//constant pointer//read only *p takes whole string as value //stores whole string addresss char *q = "ello";//constant pointer//read only char s[] = "ello";//its same as a normal variable if(p==q){//this compares address of both p & q printf("hii");

Integer Palindrome

C
3 years ago
#include <stdio.h> int main(){ int a,temp,rem,rev=0; scanf("%d",&a); for(temp=a;temp>0;temp=temp/10){ //1331 //1331 /10 = 133 //exit when loop==0 rem=temp%10; //1331%10 = 1 //133 % 10 = 3 rev=rev*10+rem; //0 * 10 + 1 = 0 + 1 => 1 // 1 * 10 + 3 = 10 + 3 => 13

Pre and post Increment

C
3 years ago
/* In C/C++, Increment operators are used to increase the value of a variable by 1. This operator is represented by the ++ symbol. The increment operator can either increase the value of the variable by 1 before assigning it to the variable or can increase the value of the variable by 1 after assigning the variable. Thus it can be classified into two types: -> Pre-Increment Operator -> Post-Increment Operator

Difference between ++*p, *p++ and *++p

C
3 years ago
/* ++*p pre increment -> only value will be incremented Here value of the variable gets inclemented to the next value after execution of the current line the value will be updated ex:- */ #include <stdio.h> ///*

UNION and Structure diff

C
3 years ago
well In structure you can think up like a class that when an object is created it consist of all the data members declared in it . say class A{ int a; float b;

Pointers

C
3 years ago
Pointers – the most powerful feature of C. In fact, it is said that without using the pointers, one can’t use C efficiently & effectively in a real world program! Pointers save memory space. Execution time with pointers is faster because data are manipulated with the address, that is, direct access to memory location. Memory is accessed efficiently with the pointers. The pointer assigns and releases the memory as well. Each variable is assigned a memory locations (the size depends on the

Hexadecimal to Binary

C
3 years ago
Decimal-hexadecimal-binary conversion table Dec Hex Bin Dec Hex Bin Dec Hex Bin Dec Hex Bin 0 0 00000000 64 40 01000000 128 80 10000000 192 c0 11000000 1 1 00000001 65 41 01000001 129 81 10000001 193 c1 11000001 2 2 00000010 66 42 01000010 130 82 10000010 194 c2 11000010 3 3 00000011 67 43 01000011 131 83 10000011 195 c3 11000011 4 4 00000100 68 44 01000100 132 84 10000100 196 c4 11000100 5 5 00000101 69 45 01000101 133 85 10000101 197 c5 110

Swap two numbers using Bitwise XOR Operator in C

C
3 years ago
/*C program to swap two numbers using bitwise operator.*/ #include <stdio.h> void swap(int* a, int* b); //function declaration int main() { int a, b;

C program to set/clear (high/low) bits of a number

C
3 years ago
/* C program to set and clear bits of a number.*/ #include <stdio.h> int main(){ int a = 10; // 0x0A a=a ^ (1<<0); // | or & printf("%d",a);

left shift operator

C
3 years ago
/* C Program to demonstrate example of left shift (<<) operator. Left Shift Operator (<<) is a bitwise operator, which perform operation on bits. It is used to shift given number of bytes in the left and inserts 0’s in the right. Binary of 0xFF in (in 4 bytes format) - 0000 0000 1111 1111. After 2 bytes left shift (in 4 bytes format) – 0000 0011 1111 1100, which is equivalent of 0x03FC.

No of set bits in a byte

C
3 years ago
/*C program to count number of 1's in a number */ #include <stdio.h> int count1s(unsigned int num); int main() { unsigned int data = 0x58; // if 0xff -> 8 printf("\nTotal number of 1's are : %d\n",count1s(data));

Swapping two Bytes/Words using C program

C
3 years ago
/* C program to swap bytes/words of integer number. How many bytes is 0xff? 0xff is a number represented in the hexadecimal numeral system (base 16). It's composed of two F numbers in hex. As we know, F in hex is equivalent to 1111 in the binary numeral system. So, 0xff in binary is 11111111. Lets break the format code "%04X" into its separate parts:

Check weather all bits are unset or not

C
3 years ago
/*Example -1 Input number: 0 Binary value: 00000000 Output: Yes, all bits are unset Example -2 Input number: 50 Binary value: 00110011 Output: No, all bits are not unset*/

Swapping the bits// get data stored bit by bit

C
3 years ago
#include <stdio.h> /* Program to swap 1st and 2nd bit of hexadecimal value stored in data variable */ int main() { unsigned char data = 0xA; // Assiging hexadecimal value since 1byte data

Bitwise Shifting set and reset bits

C
3 years ago
#include <stdio.h> int main() { int a,b,r,d,e; // set means 1 and reset means 0 scanf("%d %d",&a,&b); // for 5 3 r=(a & (1<<(b-1))); // 101 (001<<2) -> 101 & 100 = 100 -> 4 d=(a ^ (1<<(b-1)));

Bitwise basics

C
3 years ago
And gate Or gate Xor gate 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 BITWISE OPERATORS

Toggling k-th bit of a no

C
3 years ago
/* input n=5 , k=1 -> 101 toggle position 1 ... if 1 make it 0...if 0 make it 1... output = 4 -> 100 input n=2 , k=3 -> 010 toggle "" 3... output = 6 -> 110 */ #include <stdio.h>

Bit is set or not

C
3 years ago
#include <stdio.h> int main() { unsigned int var = 2; //0010 if var = 8 1000 then bit is set if((var & (1<<3)) == 0){ // 0010 & ((0001 << 3)=(1000)) // 0010 & (1000) == 0 printf("bit is not set"); } else{ printf("bit is set");