At primary stage C data types are divided into 3 categories : integer ,character and real. Let us explore these data types.

c data types
c data types

Integer :

It’s simple to understand that integer data types in C are used to store a integer value .
The basic Syntax to declare them is shown below:-
int x;
or
int x=2;
Range:Range of an integer constant is depends upon the compiler.For 64bit compilers like gcc and visual studio it’s range is -2147483648 to +2147483647 and for 16bit compilers/emulators like turboC or turboC++ the range is -32768 to +32767.

Warning:If you want to print a Integer value greater than it’s max it shows min value of Integer and vice-versa.

code:
#include<stdio.h>
int main()
{
// Double slash is use for comments
/* This format is use for multi line comments
and comments are not compiled by compiler
*/
int x;
x=2147483649;
printf(“Hello from Buffercode.in”);
if(x>2147483647){
printf(“sorry the max value of x=%dn “,x); // n is use for new line
}
else
printf(“x=%dn”,x);
return 0;
}

 Output:

Hello from Buffercode.in
x=-2147483647

Note:

  1. To display output we use the it’s inbuilt functions like printf().
  2. It is compulsory to use #include<stdio.h> at the beginning of the program.
  3. General form of printf() function:
    printf(“<format string”,list of variables);
  4. <format string> can contain:
    %d for integer values
    %f for real or floating type values
    %c for character type values

Real or Floating point numbers:
Real constants are also known as floating point numbers. These are the numbers having decimal in it Ex 123.45
These can be written in fractional form as well as exponential form .Ex 123.45(fractional) & 1.2e-4

Range of real constants and variables is from -3.4e38 to 3.4e38
Syntax:
//declaration
float x; //semicolon(“;”) is necessary after each statements
//defining variable
x=123.45;
or
float x=123.45; //defining and declaring at same time
To print:
printf(“%f “,x);
Character type:
A character is a single alphabet,digit or a special single enclosed within a single inverted commas(‘a’).
It’s max length is 1 character.
Syntax :
//declaration
char x;
//defination
x=’A’
or
char x=’A’ //declaration with defination

To print:
printf(“%c”,x);

For now it’s enough to know about C data types , In later posts we revisited them to explore C data types.

Do you have something to add or stuck somewhere in C Data Types and constants? Please share in comments.

Follow us on Facebook, Google Plus and Twitter to get more tutorials.

Previous                                      C Programming                                      Next