What is data type? A specific kind of data item, as defined by the values it can take, the programming language used, or the operations t...

Variable And Data types

/
0 Comments
What is data type?
  • A specific kind of data item, as defined by the values it can take, the programming language used, or the operations that can be performed on it.
  • Theory: 
  • C89 defines five foundational data types: character, integer, floating-point, double floating-point, and valueless. These are declared using char, int, float, double, and void, respectively. These types form the basis for several other types. The size and range of these data types may vary among processor types and compilers. However, in all cases, an object of type char is 1 byte. The size of an int is usually the same as the word length of the execution environment of the program. For most 16-bit environments, such as DOS or Windows 3.1, an int is 16 bits. For most 32-bit environments, such as Windows 95/98/NT/2000, an int is 32 bits. However, you cannot make assumptions about the size of an integer if you want your programs to be portable to the widest range of environments. It is important to understand that C stipulates only the minimal range of each data type, not its size in bytes.
  • The exact format of floating-point values will depend upon how they are implemented. Variables of type char are generally used to hold values defined by the ASCII character set. Values outside that range may be handled differently by different compilers.
  • The range of float and double will depend upon the method used to represent the floating-point numbers. Standard C specifies that the minimum range for a floating-point value is 1E–37 to 1E+37. The minimum number of digits of precision for each floating-point type is shown in Table 2-1
  • The type void either explicitly declares a function as returning no value or creates generic pointers. Both of these uses are discussed in subsequent chapters. 
  • for example:-
 int a = 5; . Int is data type a and a is variable. Its mean a will take only integer type value. that why we assign 5 .if we assign abc to a then there will we error. = is assignment operator used to assign value.



Data types:-

     o Primary(Built-in) Data Types:

           ▪ void, int, char, double and float.

   o Derived Data Types:

          ▪ Array, References, and Pointers.

    o User Defined Data Types:

          ▪ Structure, Union, and Enumeration

→ Built-in Datatypes mean the which are already define or predefine.

   void stands for Null.

   int stands for Integer like 5.

   char stands for a character like abc.

   float stands for decimal value like 0.06.

   double stands for large decimal value like 0.000006.

C  Derived Data Types means the declaration is predefine but a definition is user define.

→  User Defined Data Types means declaration and definition both defined by the user, not by the system.




What is variable?

  • Variable is nothing but a kind of bucket were we assign or store the value of data in it.
  • As you probably know, a variable is a named location in memory that is used to hold a value that can be modified by the program. All variables must be declared before they can be used. The general form of a declaration is
  • type variable_list;
  • Here, type must be a valid data type plus any modifiers, and variable_list may consist of one or more identifier names separated by commas. Here are some declarations:
  •  int i, j, l;
  •  short int si;
  •  unsigned int ui; 
  • double balance, profit, loss;
  • int a = 5;
  • int is a data type and a is an integer type of variable which stores an integer value in it. variables have three stage
  1.  declaration 
  2. definition or assignment
  3. And calling or using
→ Declaration: int a;

→  Definition : a=g;

→  Calling or Using : printf("%d",g);

Where Variables Are Declared?
  • Variables can be declared in three places: inside functions, in the definition of function parameters, and outside of all functions. These positions correspond to local variables, formal parameters, and global variables, respectively.
What is Local  Variable?
  • Variables that are declared inside a function are called local variables. In some C literature, these variables are referred to as automatic variables. This book uses the more common term local variable. Local variables can be used only by statements that are inside the block in which the variables are declared. In other words, local variables are not known outside their own code block. Remember, a block of code begins with an opening curly brace and terminates with a closing curly brace.
  • Local variables exist only while the block of code in which they are declared is executing. That is, a local variable is created upon entry into its block and destroyed upon exit. Furthermore, a variable declared within one code block has no bearing on or relationship to another variable with the same name declared within a different code block.

  • The most common code block in which local variables are declared is the function. For example, consider the following two functions: 
void func1(void)
{
int x; // local variable
x=10;
}
void func2(void)
{
int y; // local variable
y=90;
}

What is EXTERNAL (GLOBAL) Variable?






  • External variables, in contrast to automatic variables, are not confined to single functions. Their scope extends from the point of definition through the remainder of the program. Hence, they usually span two or more functions, and often an entire program. They are often referred to as global variables. 







For Any Kind of query, doubt And Error live message in cybersquad App. You will get full-time support.I will reply back within an hour.


  

No comments:

Cybercry 2018. Powered by Blogger.

Popular Posts