by Dinesh Thakur Category: Type And Variables

Generally in C program the function definition and calling takes the form as given below:

 
by Dinesh Thakur Category: Type And Variables

Declaring variables tells the compiler the data type the variable is assigned and no storage area is allocated during this stage. It is possible to assign values during declaration itself. In order to see how this can be done let us see an example.



 
by Dinesh Thakur Category: Type And Variables

First, though there can be many declarations (and in many translation units) of a single ``global'' (strictly speaking, ``external'') variable or function, there must be exactly one definition. (The definition is the declaration that actually allocates space, and provides an initialization value, if any.)

 
by Dinesh Thakur Category: Type And Variables

when a variable is not initialized in main function it contains garbage value. This can be well seen from the example below

 
by Dinesh Thakur Category: Type And Variables

Register variables: belong to the register storage class and are stored in the CPU registers. The scope of the register variables is local to the block in which the variables are defined. The variables which are used for more number of times in a program are declared as register variables for faster access.



 
by Dinesh Thakur Category: Type And Variables

Extern variables: belong to the External storage class and are stored in the main memory. extern is used when we have to refer a function or variable that is implemented in other file in the same project. The scope of the extern variables is Global.

 
by Dinesh Thakur Category: Type And Variables

Main memory and CPU registers are the two memory locations where auto variables are stored. Auto variables are defined under automatic storage class. They are stored in main memory. Memory is allocated to an automatic variable when the block which contains it is called and it is de-allocated at the completion of its block execution.



 
by Dinesh Thakur Category: Type And Variables

Register variables are stored in the CPU registers. Its default value is a garbage value. Scope of a register variable is local to the block in which it is defined. Lifetime is till control remains within the block in which the register variable is defined.



 
by Dinesh Thakur Category: Type And Variables

Static variable is a special variable that is stored in the data segment unlike the default automatic variable that is stored in stack. A static variable can be initialized by using keyword static before variable name.

 
by Dinesh Thakur Category: Type And Variables

Declaration of a variable in C hints the compiler about the type and size of the variable in compile time. Similarly, declaration of a function hints about type and size of function parameters. No space is reserved in memory for any variable in case of declaration.

 
by Dinesh Thakur Category: Type And Variables

A variable is an object whose value may change during execution of a program. It is a memory location used to store a data value. A variable name should be carefully chosen by the programmer so that its use is reflected in a useful way in the entire program. Variable names are case sensitive. Others are constants whose values cannot be changed during the execution of the program. However, their values have to be declared. In a program a variable may be declared as below.

 
by Dinesh Thakur Category: Type And Variables

If you might need large values (above 32,767 or below -32,767), use long. Otherwise, if space is very important (i.e. if there are large arrays or many structures), use short. Otherwise, use int. If well-defined overflow characteristics are important and negative values are not, or if you want to steer clear of sign-extension problems when manipulating bits or bytes, use one of the corresponding unsigned types. (Beware when mixing signed and unsigned values in expressions, though.) Although character types (especially unsigned char) can be used as "tiny'' integers, doing so is sometimes more trouble than it's worth, due to unpredictable sign extension and increased code size.

 
by Dinesh Thakur Category: Type And Variables

An object is recognized by the computer by either its identifier or name. The object may be a variable of basic type or a function, a structure, or a union. The macro names and macro variables do not figure in the scope because macros are replaced by the preprocessor token sequences before the semantic phase of program translation. An identifier may also represent different objects in different scopes.



 
by Dinesh Thakur Category: Type And Variables

Both variables and the constants may have different types of values. In C language, different forms of data are categorized into a few abstract data types. For example, suppose you are asked to keep the record of the number of passengers in a bus. A variable say N, which is used to denote this number, will have value in whole numbers because the number of passengers cannot be a fractional number. Similarly, for number of students in a class, number of apples in a basket, number of pages in a book, or number of houses in a colony, etc., the values must be in whole numbers. Whole numbers form a category called integers. In C language, this type is coded as int, a short form for integer.



 
by Dinesh Thakur Category: Type And Variables

A storage class specifies how the variables are used in the program.

 
by Dinesh Thakur Category: Type And Variables

There are many different types of data values that are implicitly declared as constants in C. The value of a constant cannot be changed during execution of the program, neither by the programmer nor by the computer. The character 'A' is a constant having numerical value equal to 65 in decimal number system.



 
by Dinesh Thakur Category: Type And Variables

Enumeration is a data type, which is coded as enum, may be used to define user's own data type and define values that the variable can take. The enumeration type is an integral data type. This can help in making program more readable. enum definition is similar to that of a structure. Its syntax is as follows:



 
by Dinesh Thakur Category: Operator

The const qualifier tells the compiler that the variable's value should not be changed once it has been initialized. If we declare a const variable as

 
by Dinesh Thakur Category: Operator

Boolean operators AND, OR, and NOT are used to manipulate logical statements. Boolean operators are the core operators used in digital control systems as well as computer systems. AND and OR are binary operators, while NOT is a unary operator. Let A and B be two logical statements or variables representing logical statements. If a logical statement is true it may be assigned the value 1, and if a logical statement is false it may be assigned the value 0. Table gives details of the three operators AND, OR, and NOT.



 
by Dinesh Thakur Category: Operator

Arithmetic operators may be combined with the assignment operator to obtain composite assignment operators. An arithmetic operator is written first followed by the assignment operator but not vice versa. In all the composite operators there should not be any blank space between the symbols. For instance, in+= if we give space between+ and= (suchas+ =),it may result in an error.

 

Page 2 of 16



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.