Basic Data types C++ HackerRank solution

A data type, in programming, is a classification that specifies which kind of value a variable has. It could be either a whole number, text, a boolean value, or even decimals. This tutorial will help you with Basic Data types C++ HackerRank solution.

Basic Data types C Basic Data types C++ HackerRank solution

Problem statement

Some C++ data types, their format specifiers, and their most common bit widths are as follows…

You can check out the complete problem on Basic Data types at HackerRank.

Also Read: Hackerrank problem on for loop


Each specific type of basic data type is previously declared before taking input individually using Cin, later they are printed with Cout. The setprecision prints up to 20 numbers including before and after the decimal, to prevent loss of information

#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;

int main() {
    int integer;
    long longint;
    char character;
    float floatnumber;
    double doublenumber;
    cin >> integer;
    cin >> longint;
    cin >> character;
    cin >> floatnumber;
    cin >> doublenumber;
    cout  << integer << endl;
    cout << longint << endl;
    cout << character << endl;
    cout << setprecision(20) << floatnumber << endl;
    cout << doublenumber << endl;
    return 0;
Sharing Is Caring:
Editorial Staff

An aspiring BTech Electronics and Communication student, obsessed with Coding, Gadgets, Blogging, & Digital Marketing.

Leave a Comment