Saturday, May 13, 2023

BITWISE OPERATOR

 BITWISE OPERATOR


In C, bitwise operators are used to perform operations at the bit level of operands. They manipulate individual bits within variables. Bitwise operators are particularly useful for low-level programming, such as working with binary data, setting/clearing specific bits, or implementing certain algorithms.

 

Here are the bitwise operators available in C:

 

1. Bitwise AND (&): Performs a bitwise AND operation on the corresponding bits of the operands. The result has a 1 bit only if both bits are 1.

   Example:

   int a = 10;   // Binary: 1010

   int b = 6;    // Binary: 0110

   int result = a & b;   // Binary result: 0010 (Decimal: 2)

 

2. Bitwise OR (|): Performs a bitwise OR operation on the corresponding bits of the operands. The result has a 1 bit if either of the bits is 1.

   Example:

   int a = 10;   // Binary: 1010

   int b = 6;    // Binary: 0110

   int result = a | b;   // Binary result: 1110 (Decimal: 14)

 

3. Bitwise XOR (^): Performs a bitwise XOR (exclusive OR) operation on the corresponding bits of the operands. The result has a 1 bit if the two bits are different.

   Example:

   int a = 10;   // Binary: 1010

   int b = 6;    // Binary: 0110

   int result = a ^ b;   // Binary result: 1100 (Decimal: 12)

  

4. Bitwise NOT (~): Performs a bitwise NOT operation, which flips the bits of the operand. Each 0 bit becomes 1, and each 1 bit becomes 0.

   Example:

   int a = 10;   // Binary: 1010

   int result = ~a;   // Binary result: 0101 (Decimal: -11, due to two's complement representation)

 

5. Left Shift (<<): Shifts the bits of the left operand to the left by the number of positions specified by the right operand.

   Example:

   int a = 5;    // Binary: 0101

   int result = a << 2;   // Binary result: 10100 (Decimal: 20)

 

6. Right Shift (>>): Shifts the bits of the left operand to the right by the number of positions specified by the right operand. It can be a logical right shift (fills with 0) or an arithmetic right shift (fills with the sign bit on signed values).

   Example:

   int a = 20;   // Binary: 10100

   int result = a >> 2;   // Binary result: 00101 (Decimal: 5)


These bitwise operators allow you to manipulate the individual bits within integers or other suitable data types. They are useful in scenarios such as setting or clearing specific bits, checking bit flags, or performing other bitwise operations.


Saturday, May 6, 2023

INCREMENT AND DECREMENT OPERATOR

 

INCREMENT AND DECREMENT OPERATOR


In C, the increment (++) and decrement (--) operators are used to increase or decrease the value of a variable by one, respectively. These operators can be applied to both integer and floating-point variables.

 

1. Increment Operator (++):

The increment operator (++) increases the value of a variable by one.

Example:

int x = 5;

x++;  // x becomes 6

In this example, the value of `x` is incremented by one using the increment operator.

 

2. Decrement Operator (--):

The decrement operator (--) decreases the value of a variable by one.

Example:

```c

int y = 7;

y--;  // y becomes 6

```

In this example, the value of `y` is decremented by one using the decrement operator.

 

Both the increment and decrement operators can be used in different contexts:

 

- Pre-increment and Pre-decrement: When the increment or decrement operator is placed before the variable (++x or --x), it is called pre-increment or pre-decrement. The value of the variable is first incremented or decremented, and then the updated value is used in the expression.

 

- Post-increment and Post-decrement: When the increment or decrement operator is placed after the variable (x++ or x--), it is called post-increment or post-decrement. The current value of the variable is used in the expression, and then the value is incremented or decremented.

 

Example:

```c

int a = 5;

int b = ++a;  // pre-increment: a becomes 6, b is assigned the value of a (6)

int c = a--;  // post-decrement: c is assigned the current value of a (6), then a becomes 5

```

 

It's important to note that using the increment or decrement operators multiple times within the same expression can lead to undefined behavior. Also, the increment and decrement operators have a higher precedence than most other operators, so their effects can be observed immediately.

Saturday, April 29, 2023

Sustainability

Sustainable innovation in coding is an essential aspect of the technology industry. As the world becomes more conscious of the impact of technology on the environment, it is crucial to focus on sustainability in the development of software and applications. Sustainable innovation in coding involves using programming techniques, software design principles, and technology tools that prioritize environmental sustainability and reduce carbon footprint. In this blog, we will discuss some of the ways sustainable innovation can be incorporated into coding practices.

  1. Writing Efficient Code: Writing efficient code is essential for reducing energy consumption and promoting sustainability in coding. By optimizing code, programmers can reduce the amount of energy required to run software applications. This can be done by using algorithms that are designed to use fewer resources, eliminating redundant code, and minimizing network requests.

  2. Minimizing Data Transfer: Data transfer is one of the most energy-consuming activities in computing. Sustainable innovation in coding involves minimizing data transfer as much as possible. This can be done by compressing data, caching frequently used data, and minimizing network requests.

  3. Using Sustainable Hosting: The hosting environment plays a significant role in the sustainability of software applications. Sustainable hosting involves using data centers that use renewable energy sources such as solar, wind, and hydropower. It is important to choose a hosting provider that has a commitment to sustainability and is transparent about its energy usage.

  4. Embracing Virtualization: Virtualization is the process of running multiple operating systems or applications on a single physical server. This reduces the number of physical servers required, which in turn reduces energy consumption and carbon footprint. Virtualization also makes it easier to scale up or down resources, which is essential for sustainable software applications.

  5. Prioritizing Modular Design: Modular design is a software design principle that involves breaking down applications into smaller, independent modules. This makes it easier to update or replace individual modules without affecting the entire application. This approach promotes sustainability by reducing the amount of code that needs to be updated or replaced when changes are made.

  6. Using Sustainable Development Tools: The development tools used to build software applications can also have an impact on sustainability. Sustainable development tools are designed to minimize energy consumption and carbon footprint. For example, using a text editor instead of an IDE can reduce energy consumption.

  7. Emphasizing Continuous Integration and Deployment: Continuous integration and deployment (CI/CD) is a software development practice that involves automating the building, testing, and deployment of software applications. This approach promotes sustainability by reducing the time and resources required to release new software versions.

Saturday, April 22, 2023

ASSIGNMENT OPERATORS

 

ASSIGNMENT OPERATORS


In C, the assignment operator is used to assign a value to a variable. It is denoted by the equals sign (=). The assignment operator assigns the value on the right-hand side to the variable on the left-hand side. Here's an example:

int x;          // Declare a variable named x

x = 5;          // Assign the value 5 to x using the assignment operator

In this example, the value 5 is assigned to the variable `x` using the assignment operator. After the assignment, the variable `x` will hold the value 5.

The assignment operator can also be combined with other operators to perform compound assignments. Here are some examples of compound assignments:

int x = 10;

x += 5;         // Equivalent to x = x + 5

x -= 3;         // Equivalent to x = x - 3

x *= 2;         // Equivalent to x = x * 2

x /= 4;         // Equivalent to x = x / 4

In these examples, the compound assignment operators (+=, -=, *=, /=) combine the arithmetic operation with the assignment operation. They perform the specified arithmetic operation and assign the result back to the variable.

It's important to note that the assignment operator works from right to left. The expression on the right-hand side is evaluated first, and then the resulting value is assigned to the variable on the left-hand side.

Saturday, April 15, 2023

LOGICAL OPERATORS

 

LOGICAL OPERATORS


Logical operators in C are used to perform logical operations on Boolean values (true or false). They allow you to combine and manipulate the results of relational or logical expressions. In C, the logical operators are:

 

1. Logical AND (&&): Returns true if both operands are true; otherwise, it returns false.

   Example:

   int a = 5;

   int b = 7;

   int c = 3;

   if (a < b && b < c)

{

       // This condition is false, so the code inside the if block will not execute.

}


2. Logical OR (||): Returns true if at least one of the operands is true; otherwise, it returns false.

   Example:

   int a = 5;

   int b = 7;

   int c = 3;

   if (a < b || b < c)

{

       // This condition is true, so the code inside the if block will execute.

}


3. Logical NOT (!): Returns the opposite of the operand's logical value. If the operand is true, it returns false; if the operand is false, it returns true.

   Example:

   int a = 5;

   int b = 7;

   if (!(a < b))

{

       // This condition is false, so the code inside the if block will not execute.

 }

 

Logical operators are commonly used to combine multiple conditions in if statements, while loops, or for loops. They help you make decisions based on complex logical expressions and control the flow of your program.

Sunday, April 9, 2023

RELATIONAL OPERATORS

 

RELATIONAL OPERATORS

 


Relational operators in C are used to compare the relationship between two operands. They evaluate the conditions and return a Boolean result, which is either true or false. Relational operators are commonly used in conditional statements and loops to make decisions based on comparisons. Here are the relational operators in C:

 

1. Equal to (==): Checks if two operands are equal.

   Example:

   int a = 5;

   int b = 7;

   if (a == b)

 { // This condition is false, so the code inside the if block will not execute.  }

 

2. Not equal to (!=): Checks if two operands are not equal.

   Example:

   int a = 5;

   int b = 7;

   if (a != b)

{   // This condition is true, so the code inside the if block will execute.}

 

3. Greater than (>): Checks if the first operand is greater than the second.

   Example:

   int a = 5;

   int b = 7;

   if (a > b)

 { // This condition is false, so the code inside the if block will not execute }

 

4. Less than (<): Checks if the first operand is less than the second.

   Example:

   int a = 5;

   int b = 7;

   if (a < b)

{  // This condition is true, so the code inside the if block will execute.}

 

5. Greater than or equal to (>=): Checks if the first operand is greater than or equal to the second.

   Example:

   int a = 5;

   int b = 7;

   if (a >= b) {  // This condition is false, so the code inside the if block will not execute. }

 

6. Less than or equal to (<=): Checks if the first operand is less than or equal to the second.

   Example:

   int a = 5;

   int b = 7;

   if (a <= b)

{ // This condition is true, so the code inside the if block will execute.}

 

Relational operators return a value of 1 (true) if the condition is satisfied, and a value of 0 (false) otherwise. These operators can be used with variables, constants, or expressions to compare values and make logical decisions in your C programs.

Sunday, April 2, 2023

Arithmetic Operators

ARITHMETIC OPERATOR

Arithmetic operators in C are used to perform basic mathematical computations on numeric operands. They allow you to add, subtract, multiply, divide, and perform other arithmetic operations. Here are the arithmetic operators in C:

1. Addition (+): Adds two operands together.

   Example: `int result = 5 + 3; // result is 8`

2. Subtraction (-): Subtracts the second operand from the first operand.

   Example: `int result = 10 - 4; // result is 6`

3. Multiplication (*): Multiplies two operands.

   Example: `int result = 6 * 2; // result is 12`

4. Division (/): Divides the first operand by the second operand. If both operands are integers, integer division is performed (any remainder is discarded).

   Example: `int result = 10 / 3; // result is 3`

5. Modulus (%): Computes the remainder of the division operation between the first operand and the second operand.

   Example: `int result = 10 % 3; // result is 1`


 



Saturday, March 25, 2023

OPERATOR AND OPERAND

   

OPERATOR AND OPERAND


In C programming, operators are symbols that perform various operations on operands. An operand, on the other hand, is a value or variable that is used in conjunction with an operator. Operators and operands are combined to form expressions, which are used to perform computations and manipulate data in a program.

Let's take a closer look at operators and operands in C:

  1. Operators: Operators in C can be classified into several categories based on their functionality. Some common types of operators include:

    • Arithmetic Operators: Perform basic arithmetic operations such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
    • Relational Operators: Compare the relationship between two operands and return a Boolean result. Examples include equal to (==), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=).
    • Logical Operators: Perform logical operations on Boolean values (true or false). These include logical AND (&&), logical OR (||), and logical NOT (!).
    • Assignment Operators: Assign values to variables. The assignment operator (=) is the most common example.
    • Increment and Decrement Operators: Increase (++) or decrease (--) the value of an operand by one.
    • Bitwise Operators: Perform operations at the bit level of operands. Examples include bitwise AND (&), bitwise OR (|), bitwise XOR (^), and bitwise NOT (~).
    • Conditional Operator: Also known as the ternary operator (?:), it provides a compact way to write conditional expressions.

  2. Operands: Operands are the values or variables on which operators act. They can take different forms, including:

    • Constants: Fixed values, such as numbers (e.g., 10, 3.14) or characters (e.g., 'A', '$').
    • Variables: Named storage locations that hold values.
    • Expressions: Combinations of operators and operands that result in a value.
    • Function Calls: Invoking a function can act as an operand, and the returned value can be used in expressions.

In C, operators and operands work together to perform computations and manipulate data according to the desired logic of the program. Understanding how to use operators and operands effectively is essential for writing correct and efficient C programs.

Sunday, March 19, 2023

Data Type

 DATA TYPE 

Definition

  1. It is a type of data which is used in the program.
  2. There are many predefined data types inc library like int, char, float, etc.  

Basic Type

Integer Type(int)

Floating Type(float)

Character Type(char)

Derived Type

Pointer

Array

Structure

Union

Integer Type  

Data Type

Size in bytes

Range

short

2

-32768 to +32767

int

2

-32768 to +32767

unsigned int

2

0 to 65536

long

4

-2147483648 to +2147483647

unsigned long int

4

0 to 4,294,967,295


Float Type

Data Type

Size in bytes

Range

float

4

3.4E-38 to 3.4E+38

double

8

1.7E-308 to 1.7E+308

long double

10

3.4E-4932 to 1.1E+4932


Character Type

Data Type

Size in bytes

Range

char

1

-128 to +127

signed char

1

-128 to -127

unsigned char

1

0 to 255


Saturday, March 11, 2023

Variables and Constant



VARIABLE

  Definition

  1. It is a name of storage space which is used to store data.
  2. It's value is changeable.
  3. It always contains last value stored to it.
  4. It is always declared with data type.
    Variable declaration
    
      int rollno;
      float marks;
      char grade;
    Here rollno is a variable of type int, marks is a variable of type float and grade is a variable of type char.

     Variable Initialisation
     
       int rollno=354;
       float marks=74.4;
       char grade='R';
     Here 354 is the value of rollno, 74.4 is the value of marks and R is the value of grade. Character value is always written in single quotes.
  
     Rules to declare a variable
  1. The first letter of a variable should be alphabet or underscore( _ ).
  2. The first letter should not be digit.
  3. After first character it may be a combination of letter or digits.
  4. Blank spaces are not allowed in variable name.
  5. Variable name should not be a keyword.
 

CONSTANT

     Definition
  1. An element of program whose value can not be changed at the time of execution of program is called constant.
  2. It is also called literals.
  3. It may be int, float and character data type.
      Rules for constructing integer constant
  1. It must have atleast one digit.
  2. It must not have decimal point.
  3. It may no be positive or negative.
  4. The range of integer constant is between -32768 to +32767.
  5. No comma or blank space are allowed in integer constant.
      Rules for constructing floating point constant
  1. It must have atleast one digit.
  2. It must have a decimal point.
  3. It may be positive or negative.
  4. No comma or blank space are allowed in floating point constant.
      Rules for constructing character constant
  1. It is a single alphabet, digit or special symbol.
  2. The length of character constant is 1 character.
  3. Character constant is enclosed within single qoutes (example:- 'A').
       Use of constants in program
      There are two ways of using constants in the C program.
  1. Using const
  2. Using #define
      Example
        
       int rollno=354;
       float marks=74.4;
       char grade='R';
      Here  354 is integer constant, 74.4 is float constant and R is character constant.
      
        

BITWISE OPERATOR

  BITWISE OPERATOR In C, bitwise operators are used to perform operations at the bit level of operands. They manipulate individual bits with...