data types in C++ programming || datatypes || variables || C++

In this, we are going to see how to assign different data-types to the variables in our C++ program.

The Code given below can be used in Turbo C++ Compiler.

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

void main()
{
    clrscr();
    // It is used to declare integer value
    int a;

    // It is used for decimal values
    float b;

    // It is used to take single letter.
    char c;
    a = 15;
    b = 2.5;
    cout<<"enter the value for variable c \n";
    cin>>c;
    cout<<"Variable 'a' is of integer type and its value is "<<a<<endl;
    cout<<"variable 'b' is of float type and its value is "<<b<<'\n';
    cout<<"variable 'c' is of character type and it is "<<c;
    getch();
}
    
    

The Code given below can be used in g++/gcc Compiler.

#include<iostream>
using namespace std;

int main()
{
    // It is used to declare integer value
    int a;

    // It is used for decimal values
    float b;

    // It is used to take single letter.
    char c;
    a = 15;
    b = 2.5;
    cout<<"enter the value for variable c \n";
    cin>>c;
    cout<<"Variable 'a' is of integer type and its value is "<<a<<endl;
    cout<<"variable 'b' is of float type and its value is "<<b<<'\n';
    cout<<"variable 'c' is of character type and it is "<<c;
    return 0;
}
    
    

To learn more about Data-types and Variables Click here.

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post