Keyword,Operators,Identifiers,Variables and datatypes

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 :

  1. main – identifier
  2. {,}, (,) – delimiter
  3. int – keyword
  4. num1, num2, sum – identifier
  5. main, {, }, (, ), int, num1, num2, sum– tokens

C operators

  1. Arithmetic Operator
  2. Increment and Decrement Operator
  3. Assignment Operators
  4. Relational Operators
  5. 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

  1. == comparative
  2. <= less than equals to
  3. >= greater than equals to
  4. > greater than
  5. < 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

  1. && (AND) operator , it is true only when all operands are true
  2. || (OR) operator , it is true when either of the operand are true
  3. ! (NOT ) operator , it is true when the operand is false
Share this on facebook

Subscribe to our Youtube Channel

Leave a comment

Your email address will not be published. Required fields are marked *