C Programming Questions and Answers

Questions Index

Question: What are different basic data types in C? Explain the need of different numeric data types with example of each.

Basic Data Type

Data Type

Type of Data

Memory

Range

int

Integer

2 Bytes

-32768 to 32767

char

Character

1 Byte

-128 to 128

float

Floating Point Number

4 Bytes

3.4e-38 to 3.4e+38

double

Floating Point Number with High Precision

8 Bytes

1.7e-308 to 1.7e+308

Data Type Qualifiers

Short, long, signed, unsigned are called the data type qualifiers and can be used with any data type. int and short int takes 2 bytes, and long int takes 4 bytes. Unsigned bits use all bits for magnitude; therefore, this type of number can be larger.

Data type

Size (bytes)

Range

Short int or int

2

−32768 to 32,767 39

long int

4

−2147483648 to 2147483647

Signed int

2

−32768 to 32767

Unsigned int

2

0 to 65535

Program using char and float data type.

/* This program demonstrates to store character
   constants in variable and display it.
*/

#include<stdio.h>
#include<conio.h>
void main()
{
    char ch;
    ch = 'A';

    printf("The value of ch : %c", ch);
    getch();
}

Output:

The value of ch : A


/* This program demonstrates how to use the format specifier %f 
   with the printf() function for floating point data.
*/

#include <stdio.h>
#include <conio.h>

void main()
{
    float number;
    
    printf("Enter a real number: ");
    scanf("%f",&number);
    printf("The number is %f",number);
    
    getch();
}

Output :

Enter a real number: 4.71
The number is 4.710000