Professional Documents
Culture Documents
OPERATORS
Comments
• A comment is an explanation or description about a piece/segment of
a code.
• A comment can helps the other programmers to understand the
program flow.
• In C Programming Language, there are two types of commenting
options, and they are Single Line and Multi-line.
• During program execution, comments or commented parts of codes
are skipped (they are not executed)
Single Line Comment
• We represent a single line comment with two forward slashes //.
• In this program, we are displaying Hello World as the C Programming
output. Here, we used a single line comment.
/* Single Line Comments in C */
#include<stdio.h>
int main()
{
// Printing Hello World Message as Output
printf(" Hello World! \n");
return 0;
}
Multi-Line Comments
• To use a multiline comment in C we use /*………….*/.The doted space represent specific
descriptions about a code segment.
• Below example describes about multiline comments.
• The Logical operators in C are some of the Operators, which are used to
combine two or more conditions.
• And perform the logical operations using && (Logical AND), ||
(Logical OR) and ! (Logical NOT)
• The Relational Operators in C are used to compare two variables, what if
we want to compare more than one condition? Very simple, C logical
operators will do the trick for you.
Logical Operators
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Bitwise operators in C Example
• Let us see one example for a better understanding of bitwise operators
in C Programming.
• In this Program, We are using two variables a and b, and their values
are 9 and 65.
• Next, we are going to use these two variables to show you various
Bitwise operations in C Language
Example
/* Bitwise operators in C Example */
#include <stdio.h>
int main()
{
int a = 9, b = 65;
printf(" Bitwise AND Operator a&b = %d \n", a & b);
printf(" Bitwise OR Operator a|b = %d \n", a | b);
printf(" Bitwise EXCLUSIVE OR Operator a^b = %d \n", a ^ b);
printf(" Bitwise NOT Operator ~a = %d \n", a = ~a);
printf(" LEFT SHIFT Operator a<<1 = %d \n", a << 1);
printf(" RIGHT SHIFT Operator b>>1 = %d \n", b >> 1);
return 0;
}
• In this bitwise operators program, We declared 2 integers a and b and
assigned the values 9 and 65.
• The binary form of 9 = 0001001 and 65 = 1000001.
• The below printf statements will perform the bitwise operations on a
and b then they will display the output
• printf(" Bitwise AND Operator a&b = %d \n", a & b);
• printf(" Bitwise OR Operator a|b = %d \n", a | b);
• printf(" Bitwise AND Operator a^b = %d \n", a ^ b);
• printf(" Bitwise NOT Operator ~a = %d \n", a = ~a);
• printf(" LEFT SHIFT Operator a<<1 = %d \n", a << 1);
• printf(" RIGHT SHIFT Operator b>>1 = %d \n", b >> 1);
• C Bitwise AND Operation = a & b
• 0001001 & 1000001 = 0000001 = 1
• C Bitwise OR Operation = a || b
• 0001001 || 1000001 = 1001001 = 73
• Next, C Bitwise Exclusive OR Operation = a ^ b
• 0001001 ^ 1000001 = 1001000 = 72
• Left Shift Operation of a Bitwise Operator = b >> 1
• 1000001 >> 1 = 0100000 = 32