This blog is under construction

Sunday, 4 March 2012

Keywords in C

What are keywords?
Keywords are set of special identifiers that are reserved by programming language itself. And they are not available to users to use as identifiers.  Keywords are also called as reserved words.

Below are the various keywords available in c programming language.
auto break case char
const continue default do
double else enum extern
float for goto if
int long register return
short signed sizeof static
struct switch typedef union
unsigned void volatile while

Note: 
keywords are always written in lower case.

Let us see how to use keywords in C program using a sample code.

 
  #include <stdio.h>
  void main() {
        int i = 0;
        const char ch = 'a';
        // value of ch is a.  So, case 'a' will be executed
        switch (ch) {
                case 'a':
                        // prints hello world for 3 times
                        for (i = 0; i < 3; i++)
                                printf("Hello world!!\n");
                        break;
                case 'b':
                        // prints hello world for 4 times
                        do {
                                printf("Hello Friend!!\n");
                                i++;
                        } while (i < 3);
                        break;

                default:
                        // prints unknow character
                        printf("Unknown character\n");
                        break;
        }
        return;
  }


  Output:
  jp@jp-VirtualBox:~$ ./a.out
  Hello world!!
  Hello world!!
  Hello world!!


Note: 
void, const, char, int, switch, case, for, while, do, break, default and return are the  keywords used in the above program.


1 comment:

  1. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete