C Tutorial
Following are the different predeined data types available in c programming,
data type | size | format code | Description |
---|---|---|---|
int | 2 bytes | %d | integer (number) |
long | 4 bytes | %ld | long integer (number) |
char | 1 byte | %c | character (single character) |
float | 4 bytes | %f | floate (decimal values) |
double | 8 bytes | %lf | double (long decimal values) |
string | - | %s | string (multiple characters) |
This c program is the example of using different data types available in c programming language.
Each data type, variable is declared, defined value and displayed in the output using printf function.
#include<stdio.h> void main() { int days = 30; long val = 34353535; char alphabet = 'a'; float unitprice = 43.5; double amount = 345353.3432; char name[20] = "codingpointer.com"; printf("\ndays: %d", days); printf("\nval: %ld", val); printf("\nalphabet: %c", alphabet); printf("\nunitprice: %f", unitprice); printf("\namount: %lf", amount); printf("\nname: %s", name); }
Output:
$ cc datatype.c $ ./a.out days: 30 val: 34353535 alphabet: a unitprice: 43.500000 amount: 345353.343200 name: codingpointer.com
This c program is used to get the size of different data types available in c programming.
#include<stdio.h> void main() { printf("\nInteger size: %d bytes", sizeof(int)); printf("\nLong integer size: %d bytes", sizeof(long)); printf("\nFloat size: %d bytes", sizeof(float)); printf("\nDouble size: %d bytes", sizeof(double)); printf("\nChar size: %d bytes", sizeof(char)); printf("\nString (character array) size: %d bytes", sizeof(char[20])); }
Output:
$ cc datatype.c $ ./a.out Integer size: 4 bytes Long integer size: 8 bytes Float size: 4 bytes Double size: 8 bytes Char size: 1 bytes String (character array) size: 20 bytes
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page