0% found this document useful (0 votes)
18 views

Lec#5

Uploaded by

mh87654332
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lec#5

Uploaded by

mh87654332
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Comments in C

Comments in C language are used to provide information about lines of code. It is widely used for
documenting code. There are two types of comments in the C language.

1. Single Line Comments


2. Multi-Line Comments

Single Line Comments:

Single line comments are represented by double slash //. Let's see an example of a single line
comment in C.

1. #include<stdio.h>
2. int main(){
3. //printing information
4. printf("Hello C");
5. return 0;
6. }
Output:

Hello C

Even you can place the comment after the statement. For example:

printf("Hello C");//printing information

Mult Line Comments:

Multi-Line comments are represented by slash asterisk \* ... *\. It can occupy many lines of code,
but it can't be nested. Syntax:

/*
code
to be commented
*/

Let's see an example of a multi-Line comment in C.

1. #include<stdio.h>
2. int main(){
3. /*printing information
4. Multi-Line Comment*/
5. printf("Hello C");
6. return 0;
7. }

Output:Hello C

Operators
Operators are symbols which are used to operate on operands to perform some action.
OR
Operator are word or symbols that cause a program to do something to variables.

The expression is the combination of operand and operator where operand may be constant or
variable.
Basic operators are +, -, *, /.

Types of Operators
The following are the some of the types of operators.
➢ Arithmetic Operator
➢ Relational Operator
➢ Logical Operator

Arithmetic Operator:
An arithmetic operator performs mathematical operations such as addition, subtraction,
multiplication, division etc. on numerical values (constants and variables).

Operator Meaning of Operator Example

+ Addition (Adds two operands) A + B = 30

Subtraction (Subtracts second operand from the A − B = 10


-
first)

A * B =
* Multiplication (Multiplies both operands.)
200

/ Division (Divides numerator by DE-numerator) B/A=2

Remainder after division (Modulus Operator and B%A=0


%
remainder of after an integer division)

++ Increment operator increases the integer value by A++ = 11


one.

-- Decrement operator decreases the integer value A-- = 9


by one.
Relational Operators:

A relational operator checks the relationship between two operands. If the relation is true, it returns
1; if the relation is false, it returns value 0.

Relational operators are used in decision making and loops.

Operator Meaning of Operator Example

== Equal to 5 == 3 is evaluated to 0

> Greater than 5 > 3 is evaluated to 1

< Less than 5 < 3 is evaluated to 0

!= Not equal to 5 != 3 is evaluated to 1

>= Greater than or equal to 5 >= 3 is evaluated to 1

<= Less than or equal to 5 <= 3 is evaluated to 0

Logical Operators:

An expression containing logical operator returns either 0 or 1 depending upon whether expression
results true or false. Logical operators are commonly used in decision making in C programming.

Operator Meaning Example

Logical AND. True If c = 5 and d = 2 then,


&& only if all operands are expression ((c==5) &&
true (d>5)) equals to 0.

Logical OR. True only If c = 5 and d = 2 then,


|| if either one operand is expression ((c==5) ||
true (d>5)) equals to 1.

Logical NOT. True


only if the operand is 0 If c = 5 then,
! (Change result from expression !(c==5) equals
true to false or from to 0.
false to true).

You might also like