Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts

Variable

Variable In C Language

Variable is used to store data. Variable is the name of the memory location .

let's see the syntax of declaration of variable:
Syntax: variable_type variable_name
Example:
  
int y;

char ch;

float per;


In Above example int, char, float are the datatype and y, ch, per is the name of variable.


We can also provide value while we declare the varable as show below:

int y=10;

char ch='B';

float a=10.5, b=5.5;//Declaring 2 variable of float type


Rules of  Declaring The Variable:
  1. Variable  can have only aphabate and unerscore.
  2. Variable can not start with digit.
  3. White space is not allowed while you declaring the variable.
Valid Variable Name:



Invalid Variable Name:


Types Of  Variable In C language:


1.Local Variable :

local variable declare inside of the function.


2.Global Variable:
 
A global variable declare outside of the function.


3.Static Variable:

Static means unchanged. A Variable declare with static keyword is called static variable.


C Programing Basic Programs

C Programing Basic Programs Using Printf() and Scanf()  Functions

Write a function called Area() Which is used to fined out are of triangel, square, circule. Use the concept of function overloading. Write a main function tha gets value from the user to test three function



#include<iostream.h>
#include<conio.h>

void area(float r)
{

float area;
area=3.65*r;
cout<<endl << "\tArea of Circule:"<<area;
}

void area(float h, float b)
{
float ans;
ans=h*b/2;
cout<<endl<<"\tArea Of Triangle:"<<ans;
}

void area(int no)
{
float ans;
ans=no*no;
cout<<endl<<"\tArea Of Square:"<<ans;
}

void main()
{
clrscr();
area(2.5f);
area(10,2.6f);
area(12);
getch();
}

  • OUTPUT:
    Area Of Circule: 9.125
    Area Of Triangle: 13
    Area Of Square: 144