Chapter 2.4 - Discuss How Variables Are Used In A Program | Part - 3


DECLARATION OF STORAGE CLASS

Variables in C can have not only data type but also storage class that provides information about their location and visibility. The storage class decides the portion of the program within which the variables are recognized. Consider the following example:


             Download Turbo C++ Program Program Complier                                                                                    

DECLARATION OF STORAGE CLASS

/* Example of storage classes */
int m;                                 
main()                                
{                                          
     int i;                            
    float balance;          
.....                          
.....                          
     functions1();            
}                                        
             function1()                        
{                                         
int i;                       
  float sum;               
.....                          
.....                          
}            


The variable m which has been declared before the main is called a global variable. It can be used in all the functions in the program. It need not be declared in the functions. A global variable is also known as an external variable. 

           C Numbers Pattern Programs With Easy Solutions

           C Star Pattern Programs With Easy Solutions
                  
The variables i, balance and sum are called local variables because they are declared insides a function. Local variables are visible and meaningful only inside the functions in which they are declared.

They are not known to other functions. Note that the variable i has been declared in both the functions. Any change in the value of i in one function does not affect its value in the other.       
C provides a variety of storage class specifiers that can be used to declare explicitly the scope and lifetime of variables. The concepts of scope and lifetime are important only in multifunction and multiple file programs and therefore the storage classes are considered in detail later when functions are discussed. For now, remember that there are storage class specifiers (auto, register, static and extern) whose meanings are given in Table 2.10.

The storage class is another qualifier (like long or unsigned) that can be added to a variable declaration as shown below:

auto int count;        
register char ch;      
static int x;           
extern long total ;  

Static and external (extern) variables are automatically initialized to zero. Automatic (auto) variables contain undefined values (known as 'garbage') unless they are initialized explicitly.


DECLARATION OF STORAGE CLASS


Chapter 2.3 - Identify the various C data types | Part -1



DATA TYPES

C language is rich in its data types. Storage representations and machine instructions to handle constants differ from machine to machine. The variety of data types available allow the programmer to select the types appropriate to the needs of the applications as well as the machine.
ANSI C supports three classes of data types:

  1. Primary (or fundamental) data types
  2. Derived data types
  3. User-defined data types
The primary data types and their extensions are discussed in this section. The user-defined data types are defined in the next section while the derived data types such as arrays, functions, structures, and pointers are discussed as and when they are encountered.
  


All C compilers support five fundamental data types, namely integer (int),  character (char), floating point (float), double-precision (double) and void. Many of them also offer extended data types such as long int and log variable. Various data types and the terminology used to describe them are given in Fig 2.4. The range of the basic four types is given in Table 2.7. We discuss briefly each one of them in this section #allaboutprogramming62.


Note:- C99 adds three more data types namely_Bool_Complex, &_Imaginary. See the Appendix "C99 Features"

Various C data types




Primary Data Types #allaboutprogramming62

Compile C program with gcc compiler in Windows 10



Compile C program with GCC compiler

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. You can compile by using the GCC command in Windows 10 Bash on Ubuntu. GCC is a key component of the GNU toolchain and the standard compiler most Unix-like operating system. 

       C Programming Tutorials for Beginners

       Downloading Programming E-BOOK

Compile C program on windows 10


1. Enable Bash on Windows 10

If you don't know how to Enable/Activate Bash on Ubuntu on Windows 10, then check out our this tutorial Learn Stepwise to Enable Win 10 Subsystem for Windows 10.






2. Install gcc compiler in Windows 10 Bash

Enter the following command in your bash terminal to Install GCC compiler in Windows 10 Bash. Installation Guide for Windows.

                                         apt-get   install gcc           

Windows 10 Bash


After successfully the compiler is installed on your Windows 10 Bash. Type the following command to verify that gcc is installed: 
                                         which gcc

Example Outputs: 

                                        /usr/bin/gcc

How to find out the version of GCC compiler


                                       gcc   --version

Install gcc compiler in Windows  Bash




3. Write your first program on bash

Use any type of TEXT EDITORS such as vim or nano to create a C program called hello.c:

                             vim hello.c   or   nano hello.c

how write program on bash


Type your lines of  programming in command screen (example):




write program lines in text editor app

After writing your program, press ctrl+o and click on  Enter key to save your program. To quiet press Ctrl + x.





4. How Compile & Run Program

Compile hello.c  C program, and create a .exe (executable) file called hello, enter:

                                           gcc   hello.c   -o   hello       

To execute program first, enter: 


                                                         ./hello

 Output:


                                       hello world

gcc compiler Windows 10

Comments System

blogger/disqus/facebook