Tutorials Logic, IN info@tutorialslogic.com

C Data Types int, float, char, void, sizeof: Tutorial, Examples, FAQs & Interview Tips

C Data Types int, float, char, void, sizeof

C Data Types int, float, char, void, sizeof is an important C Language topic because it appears in real projects, debugging sessions, and interviews. Learn the meaning first, then connect it to a small working example so the rule does not stay abstract.

For this page, focus on what problem C Data Types int, float, char, void, sizeof solves, where developers usually make mistakes, and how to verify the result. The audit note for this lesson was: under 650 content words; limited checklist/practice/mistake/FAQ notes .

A strong understanding of C Data Types int, float, char, void, sizeof should include syntax, behavior, one realistic use case, one failure case, and one quick way to check your work with tools or output.

C Data Types int float char void sizeof should be studied as a practical C Language lesson, not as a label. Start by naming the input, the rule that changes the input, and the result a learner should be able to predict after reading the page.

In the c-language > data-types page, the notes should connect the definition with a working scenario, a mistake that beginners actually make, and the exact check that proves the fix. That makes the topic useful for coding, debugging, and interview revision.

Primary Data Types

C provides several built-in data types. The size of each type may vary by platform, but the values below are typical for a 64-bit system.

Type Size Format Specifier Range Description
int 4 bytes %d or %i -2,147,483,648 to 2,147,483,647 Integer numbers
float 4 bytes %f ~3.4 x 10^-38 to 3.4 x 10^38 Single-precision decimal
double 8 bytes %lf ~1.7 x 10^-308 to 1.7 x 10^308 Double-precision decimal
char 1 byte %c -128 to 127 (or 0 to 255) Single character
void - - - No value (used for functions/pointers)

Type Modifiers

Type modifiers change the size or sign of a base type. They can be combined with int, char, and double.

Type Size Format Specifier Range
short int 2 bytes %hd -32,768 to 32,767
unsigned int 4 bytes %u 0 to 4,294,967,295
long int 4 or 8 bytes %ld -2,147,483,648 to 2,147,483,647 (min)
long long int 8 bytes %lld -9.2 x 10^18 to 9.2 x 10^18
unsigned long long 8 bytes %llu 0 to 1.8 x 10^19
unsigned char 1 byte %c 0 to 255
long double 10 or 16 bytes %Lf Extended precision

Derived Types

C also has derived data types that are built from primary types:

  • Arrays - collection of elements of the same type
  • Pointers - variables that store memory addresses
  • Structures - group of variables of different types under one name
  • Unions - similar to structures but share the same memory
  • Functions - blocks of reusable code

Declaring and Printing All Data Types

Declaring and Printing All Data Types
#include <stdio.h>

int main() {
    int    age    = 25;
    float  price  = 9.99f;
    double pi     = 3.14159265358979;
    char   grade  = 'A';

    printf("int:    %d\n",  age);
    printf("float:  %f\n",  price);
    printf("double: %lf\n", pi);
    printf("char:   %c\n",  grade);

    // Printing char as integer (ASCII value)
    printf("char as int: %d\n", grade);  // 65

    return 0;
}

/*
Output:
int:    25
float:  9.990000
double: 3.141593
char:   A
char as int: 65
*/

sizeof Operator and Type Modifiers

sizeof Operator and Type Modifiers
#include <stdio.h>

int main() {
    // sizeof returns the size in bytes
    printf("Size of char:           %zu bytes\n", sizeof(char));
    printf("Size of int:            %zu bytes\n", sizeof(int));
    printf("Size of float:          %zu bytes\n", sizeof(float));
    printf("Size of double:         %zu bytes\n", sizeof(double));
    printf("Size of long int:       %zu bytes\n", sizeof(long int));
    printf("Size of long long int:  %zu bytes\n", sizeof(long long int));
    printf("Size of unsigned int:   %zu bytes\n", sizeof(unsigned int));

    // Type modifiers in action
    unsigned int  population = 4294967295U;  // max unsigned int
    long long int bigNum     = 9223372036854775807LL;
    short int     small      = 32767;

    printf("\nunsigned int:   %u\n",   population);
    printf("long long int:  %lld\n",  bigNum);
    printf("short int:      %hd\n",   small);

    return 0;
}

/*
Output (64-bit system):
Size of char:           1 bytes
Size of int:            4 bytes
Size of float:          4 bytes
Size of double:         8 bytes
Size of long int:       8 bytes
Size of long long int:  8 bytes
Size of unsigned int:   4 bytes
*/

Detailed Learning Notes for C Data Types int, float, char, void, sizeof

When studying C Data Types int, float, char, void, sizeof, separate three things: the concept, the syntax, and the situation where it is useful. This prevents the lesson from becoming a list of commands with no practical meaning.

In C Language, C Data Types int, float, char, void, sizeof becomes easier when you build a tiny example first, then increase complexity. Add one realistic input, one invalid or boundary input, and one explanation of why the result changes.

  • Identify the main problem this topic solves.
  • Write the smallest possible working example.
  • Change one input or option and observe the result.
  • Note the mistake that would break the example.

C Data Types int float char void sizeof C review example

C Data Types int float char void sizeof C review example
#include <stdio.h>
int main(void) {
    printf("C Data Types int float char void sizeof: normal path\n");
    return 0;
}

C Data Types int float char void sizeof C boundary example

C Data Types int float char void sizeof C boundary example
#include <stdio.h>
int main(void) {
    int count = 0;
    if (count == 0) printf("C Data Types int float char void sizeof: empty input\n");
    return 0;
}
Key Takeaways
  • Explain the purpose of C Data Types int, float, char, void, sizeof before memorizing syntax.
  • Run or trace one small C Language example and confirm the output.
  • Test one normal case, one edge case, and one mistake case for C Data Types int, float, char, void, sizeof.
  • Write the rule in your own words after checking the example.
  • Connect C Data Types int, float, char, void, sizeof to a real project scenario instead of treating it as an isolated definition.
Common Mistakes to Avoid
WRONG Memorizing C Data Types int float char void sizeof without the situation where it is useful.
RIGHT Connect C Data Types int float char void sizeof to a concrete C Language task.
Purpose makes syntax easier to recall.
WRONG Testing C Data Types int float char void sizeof only with the perfect input.
RIGHT Include empty, missing, duplicate, incompatible, or failed cases when relevant.
Real bugs usually appear outside the perfect path.
WRONG Changing code before reading the visible symptom or error message.
RIGHT Inspect the output, state, configuration, or stack trace connected to C Data Types int float char void sizeof.
Evidence keeps debugging focused.
WRONG Memorizing C Data Types int float char void sizeof without the situation where it is useful.
RIGHT Connect C Data Types int float char void sizeof to a concrete C Language task.
Purpose makes syntax easier to recall.

Practice Tasks

  • Modify the example so it handles a different input or condition.
  • Write one mistake related to C Data Types int, float, char, void, sizeof, then fix it and explain the fix.
  • Summarize when to use C Data Types int, float, char, void, sizeof and when another approach is better.
  • Write a small example that uses C Data Types int float char void sizeof in a realistic C Language scenario.
  • Change one important value in the C Data Types int float char void sizeof example and predict the result first.

Frequently Asked Questions

The common mistake is memorizing syntax without understanding when the behavior changes or fails.

Remember the problem it solves in C Language, then attach the syntax or steps to that problem.

You can predict the result of a small example, explain a failure case, and choose it over a nearby alternative for a clear reason.

They often copy the syntax but skip the state, input, dependency, selector, route, type, or configuration that controls the behavior.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.