Skip to main content

C tutorial #lecture 3




Here you will be introduced to the comments in C and some basic arithmetic operations on variables and you will learn various shorthand operators.

Let's get started-

Comments in C:

Comments in C/C++ and in any other programming languages serve the purpose of improvement of readability of the code. 

Comments are enclosed within /*-----------*/. This  symbol is used for multiline comments.
For single line comments we use  // symbol  ( two backslashes)

The rules of programming language aren't applicable within comments.
The text doesn't appear in the output of the code but it appears in the source code.

It just makes the program readable for the coder.

This is a C code to illustrate comments. 
Add caption
     

Output. 

Nesting of comments:

Comments written with /*----/*---*/--------*/  can't be nested and are invalid but a comment with  /*------//------*/ can be nested. 
The following code will illustrate this. 


This error occurs if we use /*------/*--*/------*/


The same program ecxecutes if we use /* -----//-----*/

Note:- Though C language is very rich in operators as there are nearly 45                          operators but surprisingly it doesn't have any operators for                                         exponentation.

More on variables:

Variables must be declared before their use in C. 
Ex:-
Int a, b  /* declaration that a and b are integer*/
float p /* declaration that p is a float variable.*/

Arithmetic operations in variables:

Addition:  use '  +  '
   Ex:  sum=a+b; 
    Cout<<sum;

Subtraction: use ' - '
  Ex :- difference=a-b;
   Cout<<difference;

Multiplication:
 Use " * "
  Say a*b instead of a×b

Division

Use / instead of÷
 Say a/b;

Assignment operators:-(it's part of C++ ) 

C ++ provide you various shorthand operators that gives us the capability to assign  perform an operation at the same time. 

You need to know that the = operator assigns the rhs value to its lhs. 

Let's understand the shorthand operators through the code below

Int a=12;  // declaration of variables

a+=1; //  it means a=a+1

a-=1; // it means a=a-1

a*=1 // it means a=a*1

a/=1 // it means a=a/1

a%=1 // a=a%1

% is called remainder operator it gives remainder as the output.

Let's understand it through the code

 
Source code to illustrate use of% operator




Conclusion:

1. U are introduced to comments and nesting of comments. 

2. U are introduced to arithmetic operations on variables. 

3. U learnt about shorthand operators. 

4. You learnt remainder operator "%".


Did u liked it?? 
Do u have any query or any suggestions?? 








Comments

Popular posts from this blog

Python tutorial - #6 (Control statements)

Control Statements When we write a simple program, generally it executes line by line and this execution are called sequential execution. This type of execution is suitable only for developing simple programs. It is not suitable for developing complex programs. To develop a program which contains complex logic. Then we need to execute statements according to our requirement for this we uses Control statements in which we can control the statements according to our need.  ➠ There are types of control statements in Python:- a) If... statements b) If... else.. Statements c) If...elif....else.. Statements  d) While loop  e) For loop f) Nested loop  g) Else suit h) Continue statements  i) Break statements j) Pass statements  k) Assert statements l) Return statements  ↷If... statements    Syntax:-  if condition:                 Statements Here, at first...

Control structures in c #part 1 ( if statement)

The control strucures are the statements that are used to alter the flow or sequence of excecution of program.  There are basically two types of control strucures:                   1. Decision making statements a) if statement          b) if -else statement          c) switch statement 2. Loop constructs: a) for loop     b) while loop           c) do-while loop We will also study about break, continue and go to in subsequent lectures Here we will cover if statement.  Firatly u need to know the symbols for various conditions they are called relational operators.  1. ==  means here "equal to " 2. <= means here "less than Or equal to" 3. >= means here "greater than Or equal to" 4.  ! = means " Not equal to" Now u are euipped  enough to learn loops.  Let's be...

Python tutorial - #5 (Operators in Python)

Membership Operators This operator helps us to check an element is found in a sequence or not. It gives there result in Boolean value (True or False). ➥There are two types of Membership operator :- a) in b) not in ➢in membership operator This membership operator returns True if an element is found in a sequence and it returns  False When an element is not found in a sequence. Program - #1 ➢not in membership operator This membership operator returns True if an element is not found in a sequence and it returns False if an element is found in a sequence. Program = #2 Identity Operators This operator helps us to check whether two element are same or not. Actually, this operator compares the memory location of two object, if the memory locations are same then objects are also same otherwise the objects are not same.                                      ...