User-Defined Data Types in C Programming
Data Types: It is a type of data which is used in the program. There are many predefined data types in the c library like int, char, float etc. As the name, a Data-type defines the type of data being used.
When ever we define a variable or use any data in the C language program, we have to specify the type of the data, so that the compiler knows what type of data to expect.
Data types is a type of data which is used in the C program. There are many predefined data types in the C library.
Predefined data-types are integer (int), floating (float) and
character (char) etc.
Learn Best User Defined Data Types in C Language |
Primary Data Types in C
C Language provides has five basic primary data types
1. Character Data-Types: Character data types is an ASCII character set of single alphabet values like 'a' and 'A' etc.
2. Integer Data Types: Integer data types are used to store the natural whole numbers. like 1,2,4,6,100,200 etc.
3. Floating Data Types: Floating data types are store the decimal point or real numbers values store like 7.8,6.9,99.6 etc.
4. Double Data Types: Double data types can be used in very large numeric values, which are not allowed in integer or floating point data types.
5. Void Data Types: Void data types is no value. Void data types are mostly used when defining main function in C language program.
Explain Different Types of Data Types in C
There are two types of Data-types
1. Predefined Data Types
2. User Defined Data Types
Explain Basic Data Types in C Language
Basic Data Types: A basic data types are integer based and floating based data types. C Language support s both signed and unsigned literals.
The memory size of the basic data types may be changed according to 32-bit or 64-bit operating system.
Integer Data Types | Floating Data Types | Character Data Types |
---|---|---|
(int) | (float) | (char) |
Integer Data Types in C Language
Data Types | Size of Byte | Range |
---|---|---|
short | 2 | -32768 To +32768 |
int | 2 | -32768 To +32768 |
Unsigned int | 2 | 0 To 65536 |
long | 4 | -214748 To +214748 |
Unsigned long int | 4 | 0 To 4294967295 |
Float Data Types in C Language
Data Types | Size of Bytes | Range |
---|---|---|
float | 4 | 3.4E-38 To 3.4E+38 |
double | 8 | 1.7E-308 To 1.7e+308 |
Long double | 10 | 3.4E-4932 To 1.1E+4932 |
Data Types | Size of Bytes | Range |
---|---|---|
char | 1 | -128 To +127 |
Signed char | 1 | -128 To +127 |
Unsigned char | 1 | 0 To 255 |
Derived Data-Types in C
Derived Data-Types: Derived data-types that are derived from the basic data types are called derived data types.
Derived data types do not create new data types. Derived data types are derived from the primitive data types by adding some extra relational with the various elements of the primary data types.
The derived data types can be used to represent a single value or multiple values.
Array | Pointer | Structure Union |
#include<stdio.h> #include<conio.h> void main() { int a[100], n, i; printf("Enter array Size:"); scanf("%d", &n); for(int i=0;i<n;i++) { printf("Enter Array Element[%d]:", i); scanf("%d", &a[i]); } printf("Enter New Array Element Insert:"); scanf("%d", &i); a[n]=l; n++; for(int i=0;i<n;i++) { printf("New Array[%d]:%d\n",i,a[i]); } } getch(); } **********OUTPUT********** Enter array Size:5 Enter Array Element[0]:5 Enter Array Element[1]:8 Enter Array Element[2]:7 Enter Array Element[3]:4 Enter Array Element[4]:5 Enter New Array Element Insert:88 New Array[0]:5 New Array[1]:8 New Array[2]:7 New Array[3]:4 New Array[4]:5 New Array[5]:88 |
#include<stdio.h> #include<conio.h> void main() { int a=100; int *p; p=&a; printf("Value of a:%d\n", a); printf("Address of a:%d\n", &a); printf("Value of p:%d\n", p); printf("Address of p:%d", &p); **********OUTPUT********** Value of a: 100 Address of a: 828493 Value of p: 100 Address of a: 828493 |
#include<stdio.h> #include<conio.h> void msg() { printf("Welcome to Learn Coding Website"); } void main() { msg(); getch(); } **********OUTPUT********** Welcome to Learn Coding Website |
#include<stdio.h> #include<conio.h> #include<string.h> struct Employee { int id; char name[50]; int salary; }; void main() { struct Employee e[10]; int n; printf("Enter Employee Number:"); scanf("%d",&n); for(int i=0;i<n;i++) { printf("Enter Employee Id:"); scanf("%d",&e[i].id); printf("Enter Employee Name:"); scanf("%s",e[i].name); printf("Enter Employee Salary:"); scanf("%d",&e[i].salary); } printf("--------------------------------\n"); for(int i=0;i<n;i++) { printf("Employee Id:%d\n",e[i].id); printf("Employee Name:%s\n",e[i].name); printf("Employee Salary:%d\n",e[i].salary); printf("--------------------------------\n"); } getch(); } **********OUTPUT********** Enter Employee Number:1 Enter Employee Id:853 Enter Employee Name:Learn Enter Employee Salary:67454.3 -------------------------------- Employee Id:853 Employee Name:Learn Employee Salary:67454 |
#include<stdio.h> #include<string.h> union Employee { int id; char name[50]; int salary; }; int main() { union Employee e[10]; int n; printf("Enter Employee Number:"); scanf("%d",&n); for(int i=0;i<n;i++) { printf("Enter Employee Id:"); scanf("%d",&e[i].id); printf("Enter Employee Name:"); scanf("%s",e[i].name); printf("Enter Employee Salary:"); scanf("%d",&e[i].salary); } printf("--------------------------------\n"); for(int i=0;i<n;i++) { printf("Employee Id:%d\n",e[i].id); printf("Employee Name:%s\n",e[i].name); printf("Employee Salary:%d\n",e[i].salary); printf("--------------------------------\n"); } } **********OUTPUT********** Enter Employee Number:1 Enter Employee Id:654564 Enter Employee Name:Learncoding Enter Employee Salary:67557 -------------------------------- Employee Id:67557 Employee Name:s? Employee Salary:67557 |
FAQ Question Data Types
#include<stdio.h> #include<conio.h> void main() { int a=100; float b=897.67; char c='L'; printf("Integer Data types:%d\n", a); printf("Floating Data types:%f\n", b); printf("Character Data types:%c\n", c); getch(); } **********OUTPUT********** Integer Data types:100 Floating Data types:897.67 Character Data types:L |
0 Comments