Uninitialized primitive data types in C/C++ Last Updated : 11 Jun, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report What do you think happens when you use an uninitialized primitive data type? Well you may assume that the compiler should assign your primitive type variable with meaningful values like 0 for int, 0.0 for float. What about char data type?Let's find the answer to that by running the code in the IDE. CPP #include <iostream> using namespace std; int main() { // The following primitive data type variables will not // be initialized with any default values char ch; float f; int i; double d; long l; cout << ch << endl; cout << f << endl; cout << i << endl; cout << d << endl; cout << l << endl; return 0; } C #include <stdio.h> int main(void) { // The following primitive data type variables will not // be initialized with any default values char ch; float f; int i; double d; long l; printf("%c\n", ch); printf("%f\n", f); printf("%d\n", i); printf("%lf\n", d); printf("%ld\n", l); return (0); } // This code is contributed by sarajadhav12052009 Output in GFGs IDE: 5.88052e-39 0 6.9529e-310 0 Output in Codechef IDE: 0 0 0 0 Output on my machine: 1.4013e-045 0 2.96439e-323 0 Why C/C++ compiler does not initialize variables with default values? "One of the things that has kept C++ viable is the zero-overhead rule: What you don't use, you don't pay for." -Stroustrup. The overhead of initializing a stack variable is costly as it hampers the speed of execution, therefore these variables can contain indeterminate values or garbage values as memory space is provided when we define a data type. It is considered a best practice to initialize a primitive data type variable before using it in code. Comment More infoAdvertise with us Next Article User-Defined Data Types In C D darksideofthemoon Follow Improve Article Tags : C++ Practice Tags : CPP Similar Reads User Defined Data Types in C++ User defined data types are those data types that are defined by the user himself. In C++, these data types allow programmers to extend the basic data types provided and create new types that are more suited to their specific needs. C++ supports 5 user-defined data types:Table of ContentClassStructu 4 min read User Defined Data Types in C++ User defined data types are those data types that are defined by the user himself. In C++, these data types allow programmers to extend the basic data types provided and create new types that are more suited to their specific needs. C++ supports 5 user-defined data types:Table of ContentClassStructu 4 min read User-Defined Data Types In C Data Types are the types of data that can be stored in memory using a programming language. Basically, data types are used to indicate the type of data that a variable can store. These data types require different amounts of memory and there are particular operations that can be performed on them. T 4 min read Designated Initializers in C++ 20 With C++20, we get a convenient way of initializing data members. The new feature is called Designated Initializers and it might be familiar to C programmers. In other words, Designated Initializers are a new feature that has been introduced in C++20. It allows developers or programmers to initiate 5 min read Order of execution in initializer list in C++ Prerequisite: Classes, Constructors, Initializer list In this article, we will discuss the order of execution in the initializer list in C++. Generally, the order of execution is from top to bottom and left to right. But a rare condition arises where this rule fails is when the initializer list is u 2 min read C++ Static Data Members Static data members are class members that are declared using static keywords. A static member has certain special characteristics which are as follows:Only one copy of that member is created for the entire class and is shared by all the objects of that class, no matter how many objects are created. 5 min read Like