Data Types In C Programming

 Data Types In C Programming


This is C notes 2nd pdf (find all notes in ‘c programming notes’ playlist on codewithdhiru )




Variables : Attributes

All variables have three important attributes:

--A data type that is established when the variable is defined, e.g.,
integer, real, character. Once defined , the type of a C variable
cannot be changed.
--A name of the variable.
--A value that can be changed by assigning a new value to the
variable. The kind of values a variable can assume depends on
its type. For example, an integer variable can only take integer
values, e.g., 2, 100, –12.  

 

 

 

Classification : Data Types

 




 

 

Basic Data Types : Size & Range


Specifiers or Modifiers

In addition, C has four type specifiers or modifiers and three type qualifiers.

Each of these type modifiers can be applied to the base type int. The modifiers signed and unsigned can also be           applied to the base type char. In addition, long can be applied to double.When the base type is omitted from a declaration, int    is assumed.The type void does not have these modifiers.

 

Specifiers : Data Types

The specifiers and qualifiers for the data types can be broadly classified into three types:

üSize specifiers— short and long

üSign specifiers— signed and unsigned

ü Type qualifiers— const, volatile and restrict

 




Qualifiers

Modifies the properties of a variable

Controls the way variables may be accessed or modified.

Const read only variable, will never change by the program Const float pi = 3.14

§ Volatile –unexpectedly change by events outside the program (directly linked with component)

if global variable’s address is passed to clock routine of the operating system to store the system time, the value in this address keep on changing without any assignment by the program. These variables are named as volatile variable.

 

Program Statements

A statement is a syntactic constructions that performs  an action when a program is executed. All C program statements are terminated with a semi-colon (;).

 Declaration :It is a program statement that serves to communicate to the language translator information about the name and type of the data objects needed during program execution.

§ int a;

§ int b;

§ int c;

Or int a,b,c;

This line informs the C compiler that it needs to allocate space for 3 integers

§ Expression statement: It is the simplest kind of statement which is no more than an expression followed by a semicolon. An expression is a sequence of operators and operands that specifies computation of a value . Example :x = 4

§ 

Compound statement is a sequence of statements that may be treated as a single statement in the construction of larger statements.

A compound statement (also called a "block") typically appears as the body of another statement, such as the if statement

§ if ( i > 0 )

{

line[i]=x;

x++;

i--;

                     }

 

 

Lebelled Statements

 Labelled statements can be used to mark any statement so that control may be transferred to the statement by switch statement



goto label;

.. .

label: statement;

 

 

 

 

 gram Statements

Control  Statements

Control statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed. In other words, the control statements determine the ‘flow of control’ in a program.

 

 

üSelection statements allow a program to select a particular execution path from a set of one or more alternatives. Various forms of the if..else statement belong to this category.

üIteration statements are used to execute a group of one or more statements repeatedly. “while, for, and do..while” statements falls under this group.

üJump statements cause an unconditional jump to some other place in the program. Goto statement falls in this group

 

Key Words

Compiler vendors (like Microsoft, Borland ,etc.) provide their own keywords apart from the ones mentioned below. These include extended keywords like near, far, asm, etc.


Constants

§ A constant is an explicit data value written by the programmer.

Thus, it is a value known to the compiler at compiling time.

§ In ANSI C, a decimal integer constant is treated as an unsigned long if its magnitude exceeds that of the signed long. An octal or hexadecimal integer that exceeds the limit of int is taken to be unsigned; if it exceeds this limit, it is taken to be long; and if it exceeds this limit, it is treated as an unsigned long.

§  An integer constant is regarded as unsigned if its value is followed by the letter ‘u’ or ‘U’, e.g.,0x9999u;

 

Types of C Constant

constructing Integer constant




Constructing Integer constant 


nMstust have at least one digit.

q Must not have a decimal point.                                            

q Can be either positive or negative                                       

q If no sign precedes an integer constant it is assumed to be positive.

q No commas or blanks are allowed

 

Constructing Real Const in fractional form  

ERRReal constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form. Following rules must be observed while constructing real constants expressed in fractional form:

 

qMust have at least one digit.

qMust have a decimal point.

qCould be either positive or negative.

qDefault sign is positive.

qNo commas or blanks are allowed.

 

Constructing Real Const in exponential form

The exponential form of representation of real constants is usually used if the value of the constant is either too small or too large. It however doesn’t restrict us in any way from using exponential form of representation for other real constants.

 

In exponential form of representation, the real constant is represented in two parts. The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’ is called exponent.

 

Following rules must be observed while constructing real constants expressed in exponential form:

 

qThe mantissa part and the exponential part should be separated by a letter e.

qThe mantissa part may have a positive or negative sign.

qDefault sign of mantissa part is positive.

qThe exponent must have at least one digit, which must be a positive or negative integer. Default sign is positive.

 

Constructing Character constant

single alphabet, a single digit or a single special symbol enclosed within single inverted commas. Both the inverted commas should point to the left. For example, ’A’ is a valid character constant whereas ‘A’ is not.

 

The maximum length can be 1 character.

Example - ‘5’ , ‘a’ , ‘@’

 

Note : 3.2e^-5 = 3.2(10)^-5

3.14159 /* Legal */

314159E-5L /* Legal */

510E /* Illegal: incomplete exponent */

210f /* Illegal: no decimal or exponent */ .e55 /* Illegal: missing integer or fraction */

 

 

Constant example

 


DOWNLOAD PDF HERE : PDF  

 

 

 

NEXT PDF WILL COVER THE TOPIC “OPERATORS”

 

Previous
Next Post »