- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
size_t data type in C
The datatype size_t is unsigned integral type. It represents the size of any object in bytes and returned by sizeof operator. It is used for array indexing and counting. It can never be negative. The return type of strcspn, strlen functions is size_t.
Here is the syntax of size_t in C language,
const size_t var_name;
Here,
var_name − This the name of variable.
Here is an example of size_t in C language,
Example
#include <stdio.h> #include <stddef.h> #include <stdint.h> int main(void) { const size_t x = 150; int a[x]; for (size_t i = 0;i < x; ++i) a[i] = i; printf("SIZE_MAX = %lu
", SIZE_MAX); size_t size = sizeof(a); printf("size = %zu
", size); }
Output
SIZE_MAX = 18446744073709551615 size = 600
In the above program, variable x of size_t datatype is declared. An array is also declared with the size x. size_t is a datatype of unsigned integral variable x. It is calculating the size of variable a in bytes.
printf("SIZE_MAX = %lu
", SIZE_MAX); size_t size = sizeof(a);
Advertisements