c language 1st day second part


Structure of a C Program
#include <stdio.h>

int main()
{
 /* my first program in C */
printf("Hello, World! \n");


return 0;
}
#include <stdio.h>
int main()
{
Intnum;
printf("Enter a integer: ");
scanf("%d",&num); 
printf("You entered: %d",num);
return 0;
}
Operators
Operator is a symbol which perform Specific task.
Operand:- operand is a variable on which operator perform operation.
Types of Operator
1) Urinary
2) Binary
3) Tertiary
Urinary Operator:-
The Operator which acts on a single operand is called urinary operator.
Ex.
1)Increment Operator(++)
X++=11
2)Decrement Operator(--)
X--=9

int main()
{
    int r=3;
    r++;
    printf("value fo r after increment %d",r);
    return 0;
}
Int main()
{
Int c=5;
C--;
Printf(“value of c after decrement %d”,c);
Return 0;
}

Binary Operator:-
The operator which acts on two operand is called binary operator.
Arithmetic Operator
Operator
Meaning of Operator
+
addition or unary plus
-
subtraction or  unary minus
*
Multiplication
/
Division
%
remainder after division( modulo division)


#include <stdio.h>
int main()
{
int a=9,b=4,c;
    c=a+b;
printf("a+b=%d\n",c);
    c=a-b;
printf("a-b=%d\n",c);
    c=a*b;
printf("a*b=%d\n",c);
    c=a/b;
printf("a/b=%d\n",c);
    c=a%b;
printf("Remainder when a divided by b=%d\n",c);
return 0;
}

#include<stdio.h>

int main()
{
inta,b,c;
scanf("%d%d",&a,&b);
c=a+b;
printf(" The addition of  two number %d",c);
}
Assignment Operators:
The most common assignment operator is =. This operator assigns the value in right side to the left side.
Operator
Example
Same as
=
a=b
a=b
+=
a+=b
a=a+b
-=
a-=b
a=a-b
*=
a*=b
a=a*b
/=
a/=b
a=a/b
%=
a%=b
a=a%b

Relational Operator
Relational operators checks relationship between two operands. If the relation is true, it returns value 1 and if the relation is false, it returns value 0

Operator
Meaning of Operator
Example
==
Equal to
5==3 returns false (0)
> 
Greater than
5>3 returns true (1)
< 
Less than
5<3 returns false (0)
!=
Not equal to
5!=3 returns true(1)
>=
Greater than or equal to
5>=3 returns true (1)
<=
Less than or equal to
5<=3 return false (0)

#include <stdio.h>
#include<stdlib.h>
Int  main()
{
int num1=20,num2=30,result;
result=num1 > num2;
printf("the result is %d > %d=%d",num1,num2,result);
return 0;
}
Logical Operators
Logical operators are used to combine expressions containing relation operators.
Operator
Meaning of Operator
Example
&&
Logial AND 
If c=5 and d=2 then,((c==5) && (d>5)) returns false.
||
Logical OR
If c=5 and d=2 then, ((c==5) || (d>5)) returns true.
!
Logical NOT
If c=5 then, !(c==5) returns false.




Bitwise Operators
A bitwise operator works on each bit of data. Bitwise operators are used in bit level programming.
Operators
Meaning of operators
&
Bitwise AND
|
Bitwise OR
^
Bitwise exclusive OR
~
Bitwise complement
<< 
Shift left
>> 
Shift right

Ternary Operator:-
The operand which acts on three operand is called ternary operator.
Conditional Operator
Conditional operator takes three operands and consists of two symbols ?and : . Conditional operators are used for decision making .

c=(c>0)?10:-10;
If c is greater than 0, value of c will be 10 but, if c is less than 0, value of c will be -10.
Size of operator
It is a unary operator which is used in finding the size of data type, constant, arrays, structure.
#include <stdio.h>
int main(){
int a;
float b;
double c;
char d;
printf("Size of int=%d bytes\n",sizeof(a));
printf("Size of float=%d bytes\n",sizeof(b));
printf("Size of double=%d bytes\n",sizeof(c));
printf("Size of char=%d byte\n",sizeof(d));
return 0;
}


No comments