Skip to main content

Data Types

DATA TYPES in C/C++:

Since C and C++ are strongly type languages, therefore every thing must be defined. Variables are classified according to their data type, which determines the kind of information that may be stored in them.

Data TypesDescriptionC-KeywordFormat Specifier
integerIntegers are whole numbers that can have both positive and negative values but no decimal values. int
 %d or %i
FloatFloating type variables can hold real numbers precision of 6 digits.float%f
Doublecan hold real numbers with the precision of 14 digits.double%f
Characterdata type allows a variable to store only one character.char%c




Implementation in C:

#include<stdio.h>

int main()
{
     printf(“%d n”,18);                          //this will print integer
     printf(“%fn”,32.56);                    //this will print decimal number
     printf(“%d %d %dn”,32,56,89);

// %d is a place holder for integer and it provide place for one integer

     printf(“%ld”,342984092);                 // ld is user to print large integer
     printf(“n”);                                        // this is used to change lines
     printf(“%lf n”,18.5678436);         // lf is user to print large decimal (large float)
     printf(“%cn”,’A’);                         //  %c is user to print a character.

     return 0;

}

Data Types in C:

#include <stdio.h>

int main ()
{
     /*these two symbols are used to write comments
     of multiple line*/

     printf (“This is second c language programn”);
     printf (“In this program we will assign value to the variablesn”);
     printf(“%dn”,163633);
     printf(“%fn”,2.8433);
     printf(“%cn”,’H’);
     printf(“%sn”,”hello! Friends”);
     printf(“%d%c-%dnn”,45,’A’,65456);

     // %c is used for character and %s for strings.
     int age=18;                              //for assigning value to the variables
     printf(“my age is %dnn”,age);

     float height=5.8;                //for assigning decimal values
     printf(“my height is %f nn”,height);

     char My_first_name_letter=’H’;
     printf(“MY name starts with %Cnn”,My_first_name_letter);

     double pi=3.141592654;
     printf(“value of pi is %fnn”,pi);

     return 0;

}

Comments

Popular posts from this blog

Tic-Tac-Toe Implementation in Cpp (C++) Step by Step

Conditional Statement

Conditional Statement: A conditional statement is an if-then statement which means that if some statement is true then it follows the if-block of code and if the condition is false then it follows the else-block of code. In the programming world, there are two types of conditional statement namely if-else and switch. if-else Statement: Syntax: if (condition 1) { } else if (condition 2) { } else { }   Implementation of If-else statement in C: Q: Write a program to find the greatest of three numbers. #include<stdio.h> int main() { int a,b,c; printf(“Please Enter First Number “); scanf(“%d”,&a); printf(“Please Enter Second Number “); scanf(“%d”,&b); printf(“Please Enter Third Number “); scanf(“%d”,&c); if (a>b && a>c) { printf(“The Greatest Number is %d”,a); } else if (b>c) { printf(“The Greatest Number is %d”,b); } else { pr...