Data types (signed and unsigned): Numeric (int, short int, long, float, double), Character (char, string), void

A data type decides a box's size and what fits inside: int for whole numbers, float/double for decimals, char for one character, string as a char array, void for nothing, and signed/unsigned trade negative range for double the positive reach.

11 min read · 10 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Three values, three shaped boxes

The marks program is growing and today it must store three things: marks 78, percentage 78.5, and grade 'A'.

Try pouring all three into int boxes and watch: 78 fits perfectly, 78.5 loses its .5, and 'A' becomes a number you never asked for.

Boxes have shapes. Choosing the shape is what a data type does, and choosing wrong is the quietest way for a C program to lie to you.

Theory

The dabba set

A kitchen dabba set has shapes for a reason: a flat one for rotis, a tall one for dal, a tiny one for elaichi. Pour dal into the roti box and you lose half of it. Data types are the shapes: int for whole numbers, float/double for values with decimals, char for a single character. The type also fixes the box's SIZE in bytes, which decides how big a value can fit.

At a glance

The C type family (typical sizes)

TypeBytesHoldsIn the marks program
short int2Small whole numbersage
int4Whole numbersmarks = 78
long4/8Big whole numberscollege enrolment no.
float4Decimals, ~6-7 digitspercentage = 78.5
double8Decimals, ~15 digitsprecise averages
char1ONE character (as ASCII)grade = 'A'

Theory

The special ones: string, void, signed/unsigned

  • string: NOT a basic C type. Text like "Riya" is a char array, a row of char boxes, written in double quotes. Full treatment comes in Unit 3; for now, know why 'A' and "A" differ.
  • void: the "no value" type, used for functions that return nothing. No variable is declared void.
  • signed / unsigned: in a signed int, one bit stores the sign, leaving ~±214 crore. Declare unsigned int and that bit joins the value: no negatives, double the positive reach (~429 crore). Perfect for counts that can never be negative.

Practical

The marks program, properly typed

#include <stdio.h>

int main() {
    int marks = 78;
    float percentage = 78.5;
    char grade = 'A';
    unsigned int total_students = 60;

    printf("Marks: %d\n", marks);
    printf("Percentage: %f\n", percentage);
    printf("Grade: %c\n", grade);
    return 0;
}

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Quiz

You declare int percentage = 78.5; What does the box actually hold?

  1. 78, the decimal part is cut off
  2. 78.5, C adjusts the box automatically
  3. 79, C rounds to the nearest whole number
  4. 0, the program refuses the value
Show the answer

78, the decimal part is cut off

An int box has no shelf for decimals, so C truncates: the .5 is dropped, not rounded, 78.9 would also become 78. No error, no warning in most compilers, just silent data loss, which is why type choice matters. "Truncation, not rounding" is the exact phrase exams reward.

Think first

The char secret you already know

A char box is 1 byte, and bytes hold numbers. So what number sits in the box when you store 'A'? You learned this in BCA103.

Show the answer

65, the ASCII code. char is really a small number box wearing a character costume: 'A' stores 65, 'a' stores 97, '0' stores 48. That is why grade + 1 is legal C and gives 66 ('B'). Your BCA103 ASCII table just became programming equipment.

Watch out

Where marks leak

Calling string a basic data type of C: it is a char array, and examiners check. Writing sizes as universal laws: they are typical (int is "usually 4 bytes", compiler-dependent), say so. Quoting wrong: 'A' is a char, "A" is a string of two bytes (A plus a hidden end-marker). And unsigned does not mean "no sign written": it means negatives are impossible for that box.

Theory

Choosing like a professional

The working rule: whole counts → int (unsigned if negatives are impossible), money and percentages → float, science-grade precision → double, one letter/symbol → char. Get the shapes right now, because the next lesson hands you the verbs, operators, and 78 / 60 behaves very differently in int boxes versus float boxes.

Summary

Key takeaways

  • A data type fixes a box's size (bytes) and what values fit.
  • Whole numbers: short int, int, long; decimals: float (~7 digits), double (~15).
  • char holds ONE character, stored as its ASCII number; 'A' is 65.
  • string is a char array (double quotes), not a basic type; void means no value.
  • unsigned sacrifices negatives to double the positive range.
  • int boxes truncate decimals: 78.5 becomes 78, no rounding.
  • Memory hook: the dabba set, right shape for the right thing.

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction to C language

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Data types (signed and unsigned): Numeric (int, short int, long, float, double), Character (char, string), void · Computer Programming and Programming Methodology (CPPM) · Gri-Learn