Data types used in 'C' programing for SEE and NEB
Introduction:
Data types are important in defining the types of data that can be stored and manipulated by a program in 'C' programming. Understanding data types is critical for any programmer, especially those studying for the SEE (Secondary Education Examination) and NEB (National Examination Board) exams. This article delves into the data types used in 'C' programming, such as primitive data types, derived data types, and type modifiers.
Data Types in 'C' Programming Overview:
Data types refer to the type of data or variable which is to be stored and used in the program. Every variable must have a valid data type. A Data type tells the following things:- It specially or limit-up type of data or value stored in the variable.
- Data type decides the memory requirement of the variable.
- It also specifies which type of operations could perform on data.
1) Primary data types:
Basic
data types |
Data
types with type qualifiers |
Size
(bytes) |
Range |
Char |
char
or signed char unsigned
char |
1 1 |
-128
to 127 0
to 255 |
int |
int
or signed int unsigned
int short
int or signed short int unsigned
short int long
int or signed long int unsigned
long int |
2 2 1 1 4 4 |
-32768
to 32767 0
to 65535 -128
to 127 0
to 255 -2147483648
to 2147483647 0
to 4294967295 |
float |
float |
4 |
3.4E-38
to 3.4E+38 |
double |
double long
double |
8 10 |
1.7E
-308 to 1.7E+308 3.4E-4932
to 1.1E+4392 |
Following are the different data types that we use in C:
i) Character Data Type (char):
This data type is used for storing character when we
initialize the character data type then its value is single character enclosed
within single quotes.
Its Keywords
is char
Eg. Char
choice = ‘p’;
Data type
modifier:
Char data
type is used modify as :
i)
signed ii) unsigned
Eg. Signed char a;
Char
data type is also used to store string values that are represented within
double quotes " "and the variable is defined as array.
Example:
Char
name [15] =”AISHWARYA”
ii) Integer Data Type (int):
Integer data type is used with such variable that stores
integer's values. The keyword int is used to assign integer type value t the
variable.
Example:
int num = 5;
Data type modifier:
Integer
(int) data type use 4 data modifiers i.e. long, short, signed, unsigned
iii) Float Data Type (float):
This data type is used when we require to store floating point
numeric value. The keyword float is used
to assign this data type to the variable.
Example:
float
per = 75.36;
The float variable occupies 4 byte and contained the data range from to
iv) Double Data Type:
The double data type also used to store floating numeric values. It stores very large floating point numerical. It occupies 8 bytes and 10 bytes. It has two modifiers short and long. It ranges from to
Example:
double radi =
0.009;
Note: Float
doesn’t contain any modifier.
2) Secondary data types:
Following are the different types of secondary data types.
Array Data Type:
An array is a grouping of elements with the same data type. It enables the storage of multiple values under a single variable name.
For example:
int num[10]; // An array of 10 integers
Structure Data Type:
A structure is a user-defined data type that allows different types of data elements to be combined into a single entity. It allows you to represent a real-world entity or a collection of related data.For example:
struct student
{
char name[50];
int age;
float marks;
};
Union Data Type:
For example:
union data
{
int num;
float score;
char letter;
};
Format Specifier
The basic data
types can have specifiers preceding them. A type specifier alters the meaning
of data type to more precisely fit a specific need.
Following are
the different types of format specifier:
Data types |
Format specifiers symbol |
Integer |
%d |
Unsigned integer |
%u |
Octal |
%o |
Hexadecimal |
%x |
float (simple) |
%f |
float (exponential) |
%e |
Character |
%c |
String |
%s |
Character |
Meaning |
% |
First character. It is compulsory. |
_ |
minus. used for left align. |
W |
used for specifying width |
. |
dot (period), used for specifying period. |
P |
used for specifying precision |
Conclusion:
Understanding data types is essential for any programmer, but it is especially important when studying for the SEE and NEB exams. In this article, we looked at the different data types used in 'C' programming, such as integers, floating-point numbers, and characters, as well as derived data types like arrays, structures, unions, enumerated types, and the void type. We also talked about type modifiers like signed, unsigned, short, and long. Understanding these data types thoroughly will allow you to write efficient and error-free 'C' programs.
FAQs
Q1: Can we create our own data types in 'C' programming?
Q2: What is the difference between a structure and a union?
Q3: Are there any limits on the size of an array in 'C' programming?
Q4: Can we have negative values in an unsigned integer?
Q5: What does the 'void' data type indicate in 'C' programming?
No comments:
Post a Comment