Turn Desktop View Off
You are here:   HomeC Programming (Theory)Type And VariablesDefine the term Scope, Visibility And Lifetime of a Variable
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

Arithmetic Expressions

An expression is a combination of variables constants and operators written according to the syntax of C language. In C every expression evaluates to a value i.e., every expression results in some value of a certain type that can be assigned to a variable. Some examples of C expressions are shown in the table given below.

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

The simple interest on deposit is given as i= prt / 100,where p is the principle (i. e., amount deposited), r is the interest rate per annum and t is the number of years (i. e., duration of deposit). The total amount to be returned to the depositor is given as t = P + i.

Let us use the variable names deposit,rate,years,interest and tot_amt.The variable years is assumed to be of type int and all other variables to be of type float.The program given below first accepts the values of deposit,rate and years. Then it calculates the values of interest and tot_amt and prints them.

by Dinesh Thakur Category: Type And Variables

For a circle with radius r, the area and circumference are given as πr2 and 2πr respectively. Let us use variables r, area and cir of type float and a symbolic constant PI to represent the constant π. The program given below first includes the stdio.h header file and defines the symbolic constant PI. The main function initially declares the required variables and assigns value 5.0 to variable r. It then calculates the values of area and cir and prints them using the "%f" format specification.


Page 1 of 14

Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes 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.

What's New and Popular

Popular Article