Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views3 pages

Data Type

part 3 c language

Uploaded by

Dhruv Maheshwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Data Type

part 3 c language

Uploaded by

Dhruv Maheshwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

L3

INSTRUCTIONS
Instruction is what a sentence in English. Sentence is a meaningful
combination of words. Instruction too made up by combining identifiers.
The set of rules which constitutes a sentence is known as grammar. In C
language grammar is called syntax.
A program is a set of instructions. Instructions are also known as
commands or statements.

To understand instructions better, you can classify it into four types:

1. Data Type Declaration Instruction


2. Input Output Instruction
3. Arithmetic Instruction
4. Control Instruction

Data Type:
Primary objective of any program is to process data. Data is raw
information that your program manipulated to yield a meaningful
information. Data comes in various forms, name of a city is a data and
age of a person is also a data but fundamentally they are of different
nature. age is a number and you can add two numbers, multiply them
but you cannot add or multiply city names. Bottom line is, you need to
classify data on the basis of applicable operations, storage requirement,
internal representation and other factors.
When you write a program, you think of required data. You have to
understand in which category it falls. C language provides fundamental
categories of data known as data types. Of course you can create your
own data categories whenever required. You will learn about defining
your own data types in chapters covering structure, union and
enumerators.

Data types provided by C language are also known as primitive data


types. On various occasions, like during variable creation, you need to
specify its ability to hold data of which category.
To support such situations, C language provided five reserved words
(or keywords). They are known as data types.

int
char
float
double
void

As they are keywords, their meaning is known to the compiler.


The use of void is little bit different from the rest of the four, void will be
covered later in functions.

Data Type Decclaration Instruction:


One of the use of these data types is during declaration of variables.
Declaring variables is a statement telling compiler about the kind of
data that variable can hold.
Following example statements provide a glimpse of data type declaration
instruction :

int x=5, y;

float k=2.34;

char a=’y’, ch;

double d1;
Explanation:
- Each statement in C language is terminated with a semi-colon (;)
- You can use only one data type in a statement to declare variable.
- So there are four different statements to demonstrate the use of all the
data types
- statement begins with the data type, followed by the variable names
separated by commas(,)
In above example, there are six variables declared.
They are x, y, k, a, ch and d1.
- Variables declared in one statement are of same kind.
- For example x and y are both of type int, so they have common
characteristics
- Size of int type block is 4 bytes, size of float block is 4 bytes,
size of char block is 1 byte, size of double block is 8 bytes.

- So you can calculate the total memory consumption.


- It is 4 bytes for x, 4 bytes for y, 4 bytes for k, 1 byte for a, 1 byte for ch
and 8 bytes for d1.
- Data type also specify the kind of data a variable can accommodate.
int variable can contain integer constant, float and double variable can
contain real constant and char variable can contain character constant.
- Some of the variables are initialized during declaration.
Assigning values to the variables during declaration is optional.
Uninitialized variable contains unpredictable pattern of 0s and 1s,
which is known as garbage value.x contains 5, k contains 2.34,
a contains ‘y’ and rest of the variable contains garbage values.
x=5, do not read it like x is equal to 5, the correct way to read it is x
assigns 5 or 5 is assigned to x.

***In C language, ‘=’ is known as assignment operator and ‘==’ is


known as ‘equal to’ operator.

You might also like