A

@Adarsh222

Function to execute before main

C
4 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

bitwise not

C
4 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
4 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";//it

Integer Palindrome

C
4 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+

Pre and post Increment

C
4 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

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

C
4 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
4 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
4 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 ar

Hexadecimal to Binary

C
4 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 0000001

Swap two numbers using Bitwise XOR Operator in C

C
4 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
4 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
4 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 o

No of set bits in a byte

C
4 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
4 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 i

Check weather all bits are unset or not

C
4 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
4 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
4 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
4 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
4 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
4 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