Keyword,Operators,Identifiers,Variables and datatypes
C programming is a collection of keywords,operators,identifiers,variables and datatypes. The combination of all of these creates a source code which creates an executable program.
#include<stdio.h>
int main() { printf("C programs \n"); int num1 = 10, num2 = 20, sum = 0; sum = num1 + num2 ; printf("The sum of num1 and num2 is %d ",sum); return 0; }
The explanation of the above program is :
- main – identifier
- {,}, (,) – delimiter
- int – keyword
- num1, num2, sum – identifier
- main, {, }, (, ), int, num1, num2, sum– tokens
C operators
- Arithmetic Operator
- Increment and Decrement Operator
- Assignment Operators
- Relational Operators
- Logical Operators
Arithmetic Operators #include<stdio.h> int main() { printf("C programs \n"); int num1 = 10, num2 = 20, diff = 0; diff = num1 - num2 ; printf("The difference of num1 and num2 is %d ",diff); return 0; }
In this case +, – , / ,* and % (modulous )are arithmetic operators
Increment and Decrement Operator #include<stdio.h> int main() { printf("C increment and decrement operator \n"); int num1 = 10,num2 = 20; num1++; num2 --; printf("num1 after increment is %d ",num1); printf("num2 after decrement is %d ",num2); return 0; }
The ++ is called increment operator and — is called decrement operator.
Assignment Operator
- This operator consists of the following
- = equals to operator
- += this operator is the short form of sum and equals to e.g. a = a+b and can -=, *=, /=, %= .
Relational Operator
#include <stdio.h>
int main()
{
printf("C Relational Operators ");
int a = 10,b = 20;
printf("a = %d and b = %d \n",a,b);
printf("a = b is %d \n",(a==b));
printf("a < b is %d \n",(a < b));
return 0;
}
The output of the above program is
C Relational Operators a = 10 and b = 20
a = b is 0
a < b is 1
C relational operators are
- == comparative
- <= less than equals to
- >= greater than equals to
- > greater than
- < less than
C Logical Operators
#include <stdio.h>
int main()
{
printf("C Logical Operators ");
int a = 10,b = 20;
printf("a = %d and b = %d \n",a,b);
printf("a == b and a < b is %d \n",(a==b)&&(a<b));
printf("a < b or b > a is %d \n",(a < b) || (b > a));
return 0;
}
The output of the above program is
C Logical Operators a = 10 and b = 20
a == b and a < b is 0 a < b or b > a is 1
C Logical Operators a = 10 and b = 20
a == b and a < b is 0
a < b or b > a is 1
The logical operators in C are
- && (AND) operator , it is true only when all operands are true
- || (OR) operator , it is true when either of the operand are true
- ! (NOT ) operator , it is true when the operand is false
Subscribe to our Youtube Channel
Subscribe