Created: 2023-01-10 15:39
Status: #concept
Subject: Programming
Tags: C Operators JavaScript Data Types TypeScript Types GraphQL Data Types
Data Types
- It specifies what kind of data a variable will hold.
- It determines how a variable is stored (how much memory it occupies on the computer) and;
- what operations are usable on them.
int main(void) {
// declares a variable named 'height' as an <int> data type.
int height;
// declares a variable named 'profit' as a 'float' data type with the value 1.1
float profit = 1.1f;
}
See also: Integer Float Character C String C Array struct Pointer
Custom Types with typedef
Using it causes the compiler to add a new Identifier to the list of type names that it recognizes in Variable declaration, C Type Conversion casting, etc.
they are not the same as Macro Definitions!
- they have limited Block Scope while Macro Definitions extend to the entire program runtime.
Syntax
typedef <data type> Name;
<data type>
is a valid data type in Clike unsigned int
orlong double
or custom Structs.Name
is the alias of the data type that we can use in our program in place of<data type>
.
typedef int Bool;
Bool flag; // same as: "int flag;"
/* the compiler treats Bool as a synonym for int; flag is just an ordinary int */