Tuesday, July 19, 2011

Using of variables in a Program

As we know that there are three types of variables in  C and C++ programming language, and these are..

  1. Integers (.......-2,-1,0,+1,+2,..........)
  2. Floating points (e.g 2.3 ,45.5)
  3. Characters (e.g 's','a')
Variable Declaration:-
                                                               For Integers:-
                                                                                         int variable name;  
                                                               For Floating points:-
                                                                                          float variable name;
                                                               For Characters:-
                                                                                          char variable name;

Lets write a simple program that uses variables and prints it value on the screen.

#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int num;        // "num" is the variable name we can use any name here
num=14;       //here we give value to the variable  
printf("The value of num = %d",num);     //here we print the value of the variable on the screen
getch();
}

Output:-
                   The value of num = 14
Note:-
         "//" this symbol is use to give comments in C and C++ , these comments are not the part of the program it is only written for the guidance of the reader as you can see above.

No comments:

Post a Comment