8 Unnamed 01 08 2023
8 Unnamed 01 08 2023
• int a;
• int _ab;
• int a30;
• int 2;
• int a b;
• int long;
Variables in C
A variable is a name of the memory location. It is used to
store data. Its value can be changed, and it can be reused
many times.
It is a way to represent memory location through symbol
so that it can be easily identified.
int a=10,b=20;
float f=20.8;
char c='A';
33
Binary: 0,1Selvaprabhu
Dr. Poongundran 19/02/2024
#include<stdio.h>
void convert(int, int);
int main() Part1
{ int num;
printf("Enter a positive decimal number : ");
scanf("%d", &num);
printf("\nBinary number :: ");
convert(num, 2);
printf("\n");
printf("\nOctal number :: ");
convert(num, 8);
printf("\n");
printf("\nHexadecimal number :: ");
convert(num, 16);
printf("\n");
return 0;
34}/*EndDr. Poongundran Selvaprabhu 19/02/2024
of main()*/
void convert (int num, int base)
{
Part 2
int rem = num%base;
if(num==0)
return;
convert(num/base, base);
#include<stdio.h>
int main(){
float X1, X2, X3;
X1=-2.0;
X2=0.0000234 ;
X3=-0.22E-5 ; [Note: Note: E-5 = 10-5 ]
return 0;
}
5 == 3 is evaluated to
== Equal to
0
5 != 3 is evaluated to
!= Not equal to
1
5 <= 3 is evaluated to
<= Less than or equal to
41 Dr. Poongundran Selvaprabhu 0 19/02/2024
// Working of relational operators
#include <stdio.h>
int main()
{
int a = 5, b = 5, c = 10;
printf("%d == %d is %d \n", a, b, a == b);
printf("%d == %d is %d \n", a, c, a == c);
printf("%d > %d is %d \n", a, b, a > b);
printf("%d > %d is %d \n", a, c, a > c);
printf("%d < %d is %d \n", a, b, a < b);
printf("%d < %d is %d \n", a, c, a < c);
printf("%d != %d is %d \n", a, b, a != b);
printf("%d != %d is %d \n", a, c, a != c);
printf("%d >= %d is %d \n", a, b, a >= b);
printf("%d >= %d is %d \n", a, c, a >= c);
printf("%d <= %d is %d \n", a, b, a <= b);
printf("%d <= %d is %d \n", a, c, a <= c);
return 0; }
42 Dr. Poongundran Selvaprabhu 19/02/2024
Output
5 == 5 is 1
5 == 10 is 0
5>5 is 0
5 > 10 is 0
5<5 is 0
5 < 10 is 1
5 != 5 is 0
5 != 10 is 1
5 >= 5 is 1
5 >= 10 is 0
5 <= 5 is 1
5 <= 10 is 1
43 Dr. Poongundran Selvaprabhu 19/02/2024
C Logical Operators
Operator Meaning Example
If c = 5 and d = 2
Logical AND. True
then, expression
&& only if all operands
((c==5) && (d>5))
are true
equals to 0.
If c = 5 and d = 2
Logical OR. True
|| then, expression
only if either one
((c==5) || (d>5))
operand is true
equals to 1.
#include<stdio.h>
int main(){
const float PI=3.14;
printf("The value of PI is: %f",PI);
return 0;
}
output: The value of PI is: 3.140000
53 Dr. Poongundran Selvaprabhu 19/02/2024
Try this
#include<stdio.h>
int main(){
const float PI=3.14;
PI=4.5;
printf("The value of PI is: %f",PI);
return 0;
}
Output: Compile Time Error: Cannot modify a const object