Tutorialspoint.dev

Interesting facts about data-types and modifiers in C/C++

Here are some logical and interesting facts about data-types and the modifiers associated with data-types:-

1. If no data type is given to a variable, then the compiler automatically converted it to int data type.

#include <stdio.h>
int main()
{
    signed a;
    signed b;
  
    // size of a and b is equal to the size of int
    printf("The size of a is %d ", sizeof(a)); 
    printf("The size of b is %d", sizeof(b)); 
    return (0);
}

Output:

The size of a is 4
The size of b is 4

2. Signed is the default modifier for char and int data types.

#include <stdio.h>
int main()
{
    int x;
    char y;
    x = -1;
    y = -2;
    printf("x is %d and y is %d", x, y);
}

Output:



x is -1 and y is -2.

3. We can’t use any modifiers in float data type. If programmer try to use it then compiler automatically give compile time error.

#include <stdio.h>
int main()
{
    signed float a;
    short float b;
    return (0);
}

Output:

[Error] both 'signed' and 'float' in declaration specifiers
[Error] both 'short' and 'float' in declaration specifiers

4. Only the long modifier is allowed in double data types. we cant use any other specifier with double data type. If we try any other specifier then compiler will give compile time error.

#include <stdio.h>
int main()
{
    long double a;
    return (0);
}

#include <stdio.h>
int main()
{
    short double a;
    signed double b;
    return (0);
}

Output:

[Error] both 'short' and 'double' in declaration specifiers
[Error] both 'signed' and 'double' in declaration specifiers

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter