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, the compiler automatically converts it to int data type.

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <iostream>
using namespace std;
  
int main()
{
    signed a;
    signed b;
  
    // size of a and b is equal to the size of int
    cout << "The size of a is " << sizeof(a) <<endl; 
    cout << "The size of b is " << sizeof(b); 
    return (0);
}
  
// This code is contributed by shubhamsingh10

chevron_right


C

filter_none

edit
close

play_arrow

link
brightness_4
code

#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\n", sizeof(a)); 
    printf("The size of b is %d", sizeof(b)); 
    return (0);
}

chevron_right



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.

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <iostream>
using namespace std;
  
int main()
{
    int x;
    char y;
    x = -1;
    y = -2;
    cout << "x is "<< x <<" and y is " << y << endl;
}
  
// This code is contributed by shubhamsingh10

chevron_right


C

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right



Output:



x is -1 and y is -2.

3. We can’t use any modifiers in float data type. If programmer tries to use it ,the compiler automatically gives compile time error.

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <iostream>
using namespace std;
int main()
{
    signed float a;
    short float b;
    return (0);
}
//This article is contributed by shivanisinghss2110

chevron_right


C

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right



Output:

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

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

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <iostream>
using namespace std;
int main()
{
    long double a;
    return (0);
}
  
// This code is contributed by shubhamsingh10

chevron_right


C

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


C++

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <iostream>
using namespace std;
int main()
{
    short double a;
    signed double b;
    return (0);
}
  
// This code is contributed by shubhamsingh10

chevron_right


C

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right



Output:

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

This article is contributed by Bishal Kumar Dubey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Article Tags :
Practice Tags :


21


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.